首页 新闻 赞助 找找看

这段代码出现了问题,因为我刚学C++无法改正,所以请大神帮忙,感激不尽。

0
悬赏园豆:50 [已解决问题] 解决于 2015-05-10 15:12

#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;
 }
}

visMatrix的主页 visMatrix | 初学一级 | 园豆:92
提问于:2015-05-10 10:33
< >
分享
最佳答案
0

void outputInfo();

void computResult();这两句不是函数声明怎么后面加了分号呢!

主函数多了一个大括号,inputInfo少了一个大括号,这些问题改完你再试试。

还有个建议:你求平均成绩的时候用整形值除整型值合适吗?应该除50.0吧?

收获园豆:40
随风舞落 | 菜鸟二级 |园豆:259 | 2015-05-10 10:52

根据你说的,我已经把问题解决了。谢谢。请问一下整形值除以整型值是哪?如果是求平均成绩的话是除以50的。

visMatrix | 园豆:92 (初学一级) | 2015-05-10 14:51

@visMatrix: 你每个科目的平均值都定义的整形,不合适,因为平均分数大多情况下是小数!这个只是希望你的程序更严格一点,不改你的程序也对着。

随风舞落 | 园豆:259 (菜鸟二级) | 2015-05-10 19:18
其他回答(1)
0

出现了什么问题?

收获园豆:10
Firen | 园豆:5385 (大侠五级) | 2015-05-10 10:45

inputInfo函数的输出类型与main函数的输出类型不一致;已经有人回答了问题;我在他的帮助下已经解决问题了;谢谢你了。

支持(0) 反对(0) visMatrix | 园豆:92 (初学一级) | 2015-05-10 14:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册