【发布时间】:2023-02-04 14:11:14
【问题描述】:
我需要读取用户输入的数字,直到他们输入 0,打印所有输入数字的总和。
我希望得到这样的回应:
Enter n: 50
Enter n: 25
Enter n: 10
Enter n: 0
total=85
到目前为止,我的代码是(对不起我的变量):
char ya;
float tem, ye, sum, roun=0.0;
printf("Enter n: ");
scanf("%f" ,&ye);
while (ye > 0 || tem > 0)
{
printf("Enter n: ");
scanf("%f", &tem);
roun = roun + tem;
}
sum = sum + ye;
printf("Total= %f\n", sum);
【问题讨论】:
-
roun = roun + tem好像roun是总和。