我的预期结果是 average=73.5 ,我已将平均值类型设置为 double 但结果为 73 有什么问题?
#include <iostream>
using namespace std;
int main(){
int x=0;
int total=0;
double average=0;
int counter=0;
cout<<"Question 1"<<endl<<"Enter integer(-100 to end);";
cin>>x;
if (x!=-100)
{
for(;x!=-100;counter++)
{
total=total+x;
cin>>x;
}
average = total/counter;
}
cout<<"The average is:"<<average<<endl;
return 0 ;
}