注册 登录
编程论坛 C++教室

[求助]大家帮我看看这个程序

玻璃水草 发布于 2007-04-05 21:27, 494 次点击
要编写这样个程序,允许用户输入学生的名字,后面是测试分数,然后输出(假设班级中最多的认输是50):
1。班级平均分
2。所有分数低于平均分的学生名字逼供内显示出相应的一条信息。
3。最高测试分数和所有获得测试最高分数的学生名字

我自己写的如下:
#include "iostream.h"
const int count=50;
int main()
{
double score[count];
char name[count];
double sum;
int i;
double highestScore=0;
double averageScore;
cout<<"Enter "<<count<<"names:"<<endl;
cout<<"Enter "<<count<<"scores:";
for(i=0;i<count;i++)
{
cin>>name[i];
cout<<endl;
cin>>score[i];
cout<<endl;
}
//求平均分//
for(i=0;i<count;i++)
sum=sum+score[i];
averageScore=sum/count;
cout<<"averageScore is:"<<averageScore<<endl;
//低于平均分的人//
for(i=0;i<count;i++)
{
if(score[i]<averageScore)
cout<<"Scores lower than averageScore:"<<endl;
}
//输出最高分数//
for(i=0;i<=count;i++)
{
if (highestScore<=score[i])
highestScore=score[i];}
cout<<score[i]<<name[i];


return 0;

}
我哪些地方错了啊,我是菜菜鸟,大家帮帮忙

5 回复
#2
玻璃水草2007-04-05 21:29
我的这个环境中不能写上using namespace std
也不能用string,是怎么回事情啊?
#3
玻璃水草2007-04-05 21:34
`自己先把输出最高分数的地方改下
//输出最高分数//
for(i=0;i<=count;i++)
{
if (highestScore<=score[i])
{ highestScore=score[i];
j=i;}
cout<<score[j]<<name[j];
}
#4
yuyunliuhen2007-04-05 21:58
以下是引用玻璃水草在2007-4-5 21:27:21的发言:
要编写这样个程序,允许用户输入学生的名字,后面是测试分数,然后输出(假设班级中最多的认输是50):
1。班级平均分
2。所有分数低于平均分的学生名字逼供内显示出相应的一条信息。
3。最高测试分数和所有获得测试最高分数的学生名字

我自己写的如下:
#include "iostream.h"
const int count=50;
int main()
{
double score[count];
char name[count];
double sum;
int i;
double highestScore=0;
double averageScore;
cout<<"Enter "<<count<<"names:"<<endl;
cout<<"Enter "<<count<<"scores:";
//for(i=0;i<count;i++) //这个";"在简体中文的状态下输入的吧,要在英文状态下输入;
for(i=0;i<count;i++)
{
cin>>name[i];
cout<<endl;
cin>>score[i];
cout<<endl;
}
//求平均分//
for(i=0;i<count;i++)
sum=sum+score[i];
averageScore=sum/count;
cout<<"averageScore is:"<<averageScore<<endl;
//低于平均分的人//
for(i=0;i<count;i++)
{
if(score[i]<averageScore)
cout<<"Scores lower than averageScore:"<<endl;
}
//输出最高分数//
for(i=0;i<=count;i++)
{
if (highestScore<=score[i])
highestScore=score[i];}
cout<<score[i]<<name[i];


return 0;

}
我哪些地方错了啊,我是菜菜鸟,大家帮帮忙

可以编译运行了

#5
yuyunliuhen2007-04-05 21:59
以下是引用玻璃水草在2007-4-5 21:29:03的发言:
我的这个环境中不能写上using namespace std
也不能用string,是怎么回事情啊?

你用的什么编译器啊?

#6
玻璃水草2007-04-06 09:45
我是用的turbo c for Windows
1