#include <iostream>
#include <array>
int main() {
using namespace std;
cout<<"Enter 10 donation value(non-numeric to quit):"<<endl;
array<float,10> ar;
int i=0;
float sum=0;
float ave;
while(i<10&&cin>>ar[i])
{
sum+=ar[i];
++i;
}
if(i==0)
cout<<"Error! i can't be 0!"<<endl;
else
{
ave=sum/i;
int n_big=0;
for(int k=0;k<i;++k)
if(ar[k]>ave)
++n_big;
cout<<"The average of the numbers is: "<<ave<<endl;
cout<<n_big<<" number(s) is(are) bigger than average "<<ave<<endl;
}
return 0;
}
C++ primer plus 6th 6.2答案
最新推荐文章于 2025-12-01 13:12:33 发布
本文介绍了一个使用C++编程语言实现的程序,该程序能够接收用户输入的10个捐赠数值,计算并输出这些数值的平均值,并进一步统计并显示高于平均值的数值数量。通过使用标准输入输出流和数组,程序展示了基本的数据处理和条件循环控制结构。
232

被折叠的 条评论
为什么被折叠?



