我试图让 averageInt 正常工作。截至目前如果我输入:10(回车键)20(回车键)30(回车键)40(回车键)50(回车键)L 平均打印:10
答案应该是 30。我不明白它如何返回 10。
#include <stdio.h>
#include <math.h>
int main ()
{
//variable declarations
int minInt = 10, maxInt = 0, averageInt=0, numDivBy7 = 0, numGreat15 = 0;
int userInt = 0, sumOfInt = 0, count = 0;
//prompting user for values
printf("Enter integers (enter a character to terminate): ");
//while loop
while (scanf(" %d",&userInt) == 1 )
{
count++;
if (userInt<minInt)
minInt=userInt;
if (userInt>maxInt)
maxInt=userInt;
sumOfInt =+ userInt;
averageInt = (double)sumOfInt/count;
if (userInt%7 == 0)
numDivBy7++;
if (userInt > 15)
numGreat15++;
printf("Enter another integer (enter a character to terminate): ");
}
if (maxInt == 0 && minInt == 10)
printf("The user entered no integers\n");
else
{
printf("Min: %.2d\tMax: %.2d\tAverage: %.2d",minInt,maxInt,averageInt);
printf("\nDivisable by 7: %.2d\tGreater than 15: %.2d\n",numDivBy7,numGreat15);
}
//terminate
return 0;
}