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

C++求平均值 有关问题·····

2012-04-16 
C++求平均值 问题#include stdafx.h#include iostream#include string#include cctypeint main(){

C++求平均值 问题·····
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cctype>
int main()
{
using namespace std;
const int cc=10;
double cci[cc];
double shu=0;
int i,x=0;

for (i=0;i<cc;i++)
{
while(!(cin>>cci[i]))
{
break;
}
shu+=cci[i];
}

int f=0;
for (int j=0;j<=x;j++)
{
if ((shu/i)<cci[j])
{
f++;
}
}
cout<<"平均值为:"<<shu/i<<endl;
cout<<"有"<<f<<"个大于平均值"<<endl;
return 0;
}
结果不对 求大大 更正·····

[解决办法]
第二个for循环应该是这个吧

C/C++ code
for (int j=0;j<=cc;j++)
[解决办法]
楼主你的X是想做什么的?这里值是0,下面这个for循环不会跑,可以把 j<=x 改成

j < cc;

for (int j=0;j<=x;j++)

热点排行