有5个学生,每个学生的数据包括学号、姓名、三门课成绩,从键盘输入5个学生的数据,要求计算并输出: (1)每个学生三门课的总成绩; (2)三门课每门课程的平均成绩。

问题描述:

根本不能输入数据。后面运行全都是0的显示。

#include<iostream>
using namespace std;
#define STUDENT struct student
STUDENT
{
  int num;
  char name[20];
  float score1;
  float score2;
  float score3;
};
STUDENT student[5];
int i;
void main()
{
 for(i=0;i<5;i++)
  
  cin>>student[i].num;
     cin>>student[i].name;
  cin>>student[i].score1;
  cin>>student[i].score2;
  cin>>student[i].score3;
  cout<<endl;
 float x,y,a,b;
 for(i=0;i<5;i++)
 {
  x=student[i].score1+student[i].score2+student[i].score3 ;
  cout<<"总和"<<x<<endl;
 }
 y=(student[0].score1+student[1].score1+student[2].score1+student[3].score1+student[4].score1)/5;
 a=(student[0].score2+student[1].score2+student[2].score2+student[3].score2+student[4].score2)/5;
 b=(student[0].score3+student[1].score3+student[2].score3+student[3].score3+student[4].score3)/5;
 cout<<"第一门课的平均成绩"<<y<<endl;
 cout<<"第二门课的平均成绩"<<a<<endl;
    cout<<"第一门课的平均成绩"<<b<<endl;
}

16行的for循环你得加{}啊


for(i=0;i<5;i++)
{
  cin>>student[i].num;
  cin>>student[i].name;
  cin>>student[i].score1;
  cin>>student[i].score2;
  cin>>student[i].score3;
}