关于continue和平均数的问题
double sum = 0;int tmp = 0;
int i = 0;
while ( 1 )
{
printf("please input a number: ");
scanf("%d",&tmp);
if ( tmp ==0 )
break;
else if (tmp<0)
{
printf("only positive numbers are accepted\n");
}
continue;
sum += tmp;
i++;
}
printf("the average is %0.2lf",sum/i );
return 0;
}
请问大大,哪里有问题
输入2 2 -1 0
结果很奇怪。。the average is -1.#J