☜丘比特☞ 2021-12-12 19:34 采纳率: 100%
浏览 516
已结题

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

  • 写回答

1条回答 默认 最新

  • 关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月23日
  • 已采纳回答 12月15日
  • 创建了问题 12月12日

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决