我一直在尝试对我的程序进行错误检查,scanf 使用 while 循环,但我不确定如何执行此操作。
我想确保用户输入的评委人数在 4 到 8 之间,并且分数不低于 0 或高于 10。
有人可以帮帮我吗?
谢谢!
#include <stdio.h>
int i,j,k, judges;
float max, min,total;
int main(){
max = 0.0;
min = 10.0;
judges = 0;
total = 0;
printf("Enter number of judges between 4-8: ");
scanf("%d", &judges);
float scores[judges];
for(i = 0; i < judges; i++){
printf("Enter a score for judge %d : ", i + 1);
scanf("%5f", &scores[i]);
}
for(j = 0; j < judges; j++){
if(min > scores[j]){
min = scores[j];
}
if (max < scores[j]){
max = scores[j];
}
}
for(k = 0; k < judges; k++){
total = total + scores[k];
}
total = total-max-min;
printf("max = %4.1f min = %4.1f total = total = %4.1f", min, max,total);
}