#include <iostream>
using namespace std;
struct student_info
{
string strName;
int chinese;
int math;
int english;
};
student_info student[50];
void inputInfo()
{
int i=0;
char a[20];
for( i=0; i<50; i++)
{
cout<<"Enter the"<<i+1<<"student's information:"<<endl;
cout<<"Enter name:"<<endl;
cin>>a;
student[i].strName=a;
cout<<"Enter Chinese performance:"<<endl;
cin>>student[i].chinese;
cout<<"Enter Math performance:"<<endl;
cin>>student[i].math;
cout<<"Enter English performance:"<<endl;
cin>>student[i].english;
}
void outputInfo();
{
int i=0;
for( i=0; i<50; i++)
{
cout<<"The"<<i+1<<"student's information:"<<endl;
cout<<"Name:"<<student[i].strName.c_str()<<endl;
cout<<"Chinese performance:"<<student[i].chinese<<endl;
cout<<"Math performance:"<<student[i].math<<endl;
cout<<"English performance:"<<student[i].english<<endl;
}
}
void computResult();
{
int avgChinese=0;
int avgMath=0;
int avgEnglish=0;
int total=0;
int i=0;
while(i<50)
{
total += student[i].chinese;
i++;
}
avgChinese=total/50;
total=0;
i=0;
while(i<50)
{
total += student[i].math;
i++;
}
avgMath=total/50;
total=0;
i=0;
while(i<50)
{
total +=student[i].english;
i++;
}
avgEnglish=total/50;
cout<<"Enter 1 for look up the average of Chinese.\n"
<<"Enter 2 for look up the average of Math.\n"
<<"Enter 3 for look up the average of English.\n";
cin>>i;
switch(i)
{
case 1:
cout<<"Average of Chinese is:"<<avgChinese<<endl;
break;
case 2:
cout<<"Average of Math is:"<<avgMath<<endl;
break;
case 3:
cout<<"Average of English is:"<<avgEnglish<<endl;
break;
default:
cout<<"Please enter 1,2or3"<<endl;
break;
}
}
int main()
{
inputInfo();
outputInfo();
computResult();
cin.get();
return 0;
}
}
void outputInfo();
void computResult();这两句不是函数声明怎么后面加了分号呢!
主函数多了一个大括号,inputInfo少了一个大括号,这些问题改完你再试试。
还有个建议:你求平均成绩的时候用整形值除整型值合适吗?应该除50.0吧?
根据你说的,我已经把问题解决了。谢谢。请问一下整形值除以整型值是哪?如果是求平均成绩的话是除以50的。
@visMatrix: 你每个科目的平均值都定义的整形,不合适,因为平均分数大多情况下是小数!这个只是希望你的程序更严格一点,不改你的程序也对着。
出现了什么问题?
inputInfo函数的输出类型与main函数的输出类型不一致;已经有人回答了问题;我在他的帮助下已经解决问题了;谢谢你了。