首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

自己做了道题,但结果不对,请迷津

2012-03-13 
自己做了道题,但结果不对,请高手指点迷津#includeiostream#includecctypeconstintmaxv10intmain(){u

自己做了道题,但结果不对,请高手指点迷津
#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,是计算所有

热点排行