怎么利用结构输入学生成绩,然后输出前三名。看看我的代码那里错了,发现不了,呜呜呜 - 爱问答

(爱问答)

怎么利用结构输入学生成绩,然后输出前三名。看看我的代码那里错了,发现不了,呜呜呜

#include"stdafx.h"

#include<iostream>

using namespace std;

#include<stdio.h>

#define N 3

#include<iomanip>

struct student 

{

char name[20];

int stu_number;

int score[3];

int sum;

};

int main()

{

cout.precision(4);

struct student stua[N];

for(int i=0;i<N;i++)

{

stua[i].sum=0;

cout<<"please input student'name number and english math chinese score"<<endl;

cin>>stua[i].name;

cin>>stua[i].stu_number;

for(int k=0;k<3;k++)

{

cin>>stua[i].score[k];

stua[i].sum=stua[i].sum+(stua[i].score[k]);

}

}

for(int j=0;j<N;j++)

{

 

for(int i=j+1;i<N-1;i++)

{

if(stua[i].sum>stua[j].sum)

{

stua[-1]=stua[i];

stua[i]=stua[j];

stua[j]=stua[-1];

}

}

}

for(int i=0;i<3;i++)

{

cout<<stua[i].name<<"    "<<stua[i].sum/3<<endl;

}

}


不看其它的
你的 stua[-1]明显的下标溢出

(C++下标溢出的结果是不可预见的,这个是程序员最怕的BUG,你居然用它,不知你哪里学来的)

另外,你既然用C++,就应该了解C++本身有排序,不用自己写的

下一篇:支付宝注册新用户及领红包

上一篇:JAVA:制作一个评选优秀老师和学生的系统,系统根据提示输入类别(老师或学生),如果是老

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?