自己做了道题,但结果不对,请高手指点迷津
#include <iostream>
#include <cctype>
const int maxv=10;
int main()
{
using namespace std;
double donation[maxv];
int i=0;
double num=0;
double total=0;
for (i=0;i <maxv;i++)
{
cout < < "Enter the donation # " < <i+1 < < ": " < <endl;
if(!(cin> > donation[i]))
break;
else total+=donation[i];
num+=1;
}
double avr=total/num;
int n=0;
for (int j=0;j <maxv;j++)
{
if(avr <donation[j])
n+=1;
}
cout < <total < <endl;
cout < <num < <endl;
cout < < "The avrange is " < <avr < <endl;
cout < < "There is " < <n < < " donations larger than the avrange. ";
return 0;
}
要求是输出大于平均数的个数,但我做出来却总是所有元素个数,想不明白,请大家指点下啊
[解决办法]
for (int j=0;j <maxv;j++)
{
if(avr <donation[j])
n+=1;
}
//你正确输入的个数是num,你用maxv,是计算所有