求大神解答一下哪里有问题

2301_78618167 2023-06-09 11:16:23

 

...全文
170 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CSDN-Ada助手 2023-06-09
精选
  • 打赏
  • 举报
回复
您的问题已经帮您同步至问答, 链接: https://ask.csdn.net/questions/7960967, 请您保持关注, 如果回答有帮助解决此问题, 麻烦您动动小手给相关的回答点赞, Ada会在评论区为您更新结题状态
yo~Magee 2023-06-09
  • 打赏
  • 举报
回复 1

1、结构体里没有“英语成绩”
2、main函数第一个for循环中第一个输入cin>>studentS,这个变量名写错了
3、第二个for前面变量声明的时候空格丢个
4、最后输出名字的时候变量名又写错了

#include <iostream>
#include <string> 

using namespace std;

struct Student {
    string name;
    float c_s;
    float m_s;
    float eh_s;
    float avg_s;
}; 

int main() {
    Student students[3];
    for (int i=0; i<3; i++) {
        cout<< "input the "<< i+1 <<"student name:";
        cin >> students[i].name;
        cout<< "input Ch score:";
        cin >> students[i].c_s;
        cout<< "input math score:";
        cin >> students[i].m_s;
        cout<< "input eh score:";
        cin >> students[i].eh_s;
        students[i].avg_s = ( students[i].c_s + students[i].m_s + students[i].eh_s )/3.0;
    } 
    
    int max_index = 0;
    
    for (int i=1; i<3; i++) {
        if (students[i].avg_s > students[max_index].avg_s) {
            max_index=i;
        }
    }
    
    cout << "max " << students[max_index].name << endl;
    cout << "avg score " << students[max_index].avg_s << endl;
}
2301_78618167 2023-06-09
  • 打赏
  • 举报
回复

球球了

70,014

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧