#include<iostream>
const int Max = 10;
int main()
{
using namespace std;
double donation[Max];
double average;
int i,j;
double total=0.0,count=0.0;
cout<<"Enter 10 numbr: \n";
for(i=0;i<Max;i++)
cin>>donation[i];
while(i<Max && cin>>donation[i]);
{
for(j=0;j<i;j++)
{
total+=donation[j];
average=total/i;
if(donation[j]>average)
count++;
}
cout<<"The average of number: "<<average<<endl;
cout<<count<<" number more than average";
}
return 0;
}
为什么最后求大于平均数的数有多少时,显示的是所有数有多少?
const int Max = 10;
int main()
{
using namespace std;
double donation[Max];
double average;
int i,j;
double total=0.0,count=0.0;
cout<<"Enter 10 numbr: \n";
for(i=0;i<Max;i++)
cin>>donation[i];
while(i<Max && cin>>donation[i]);
{
for(j=0;j<i;j++)
{
total+=donation[j];
average=total/i;
if(donation[j]>average)
count++;
}
cout<<"The average of number: "<<average<<endl;
cout<<count<<" number more than average";
}
return 0;
}
为什么最后求大于平均数的数有多少时,显示的是所有数有多少?