变量值如何获取的最大最小值
新手求教,以下程序变量min,max如何实现获得最大最小值,所有输入值看着程序上并未比较啊!#include<stdio.h>
int main(void)
{
const float MIN=0.0f;
const float MAX=100.0f;
float score;
float total=0.0f;
int n=0;
float min=MAX;
float max=MIN;
printf("Enter the first score (q to quit):");
while(scanf("%f",&score)==1)
{
if(score<MIN||score>MAX)
{
printf("%0.1f is an invaild value. Try again: ",score);
continue;
}
printf("Accept %0.1f:\n",score);
min=(score<min)?score:min;
max=(score>max)?score:max;
total+=score;
n++;
printf("Enter next score (q to quit):");
}
if(n>0)
{
printf("Average of %d score is %0.1f.\n",n,total/n);
printf("Low=%0.1f,High=%0.1f\n",min,max);
}
else
printf("No valid scores were entered.\n");
system("pause");
return 0;