从 Windows 开始,我开始使用 linux 编写 C 语言。
我的问题是如何停止或重置计算。
像这里:(示例)
#include <stdio.h>
#include <conio.h>
main(){
int average;
int total;
int number;
int loopcount;
loopcount=0;
system("clear");
while(loopcount<3){
printf("Enter a number:");
scanf("%d",&number);
total=total+number;
loopcount=loopcount+1;
}
average=total/3;
printf("the average is %d", average);
getch();
}
输出:输入一个数字:1 输入一个数字:1 输入一个数字:1 平均值是 1。但是当我再次运行它时,最后计算的平均值会添加到我的新平均值中。我应该如何或在我的代码中输入什么来阻止这种情况。
? 我试过谷歌,但找不到确切的关键字。天呐!