我正在从事的这个程序是这样的:计算你同学的平均高度。 输入以英尺和英寸为单位的高度。 验证英尺在 3-8 范围内,英寸在 0 到 <12 范围内。 显示学生人数和平均高度。 这是我到目前为止所得到的,但是,我不知道这是否是处理它的正确形式。我现在有货。
#include <stdio.h>
int main( void )
{
char another;
int feet;
double inches, total = 0, average;
printf( "Do you have a student? (y/n)" );
scanf( "%\n%c", &another );
while ( another == 'y' )
{
do
{
printf( "Enter inches: " );
scanf( "%lf", &inches );
}
while ( inches < 0 || inches >= 12 );
printf( "Do you have a student? (y/n)" );
scanf( "%\n%c", &another );
}
return 0;
}
最佳答案
“另一个”字符的 scanf
格式应该是“%c”。否则,它对我来说看起来是正确的。
关于C 编程循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21892141/