使用结构体类型编写一程序,实现输入五个同学的成绩,然后计算并输出平均成绩和最高分。

如题所述

第1个回答  2012-05-27
#include <iostream>
#include <string>

using namespace std;

struct student{
string name;//可以自行设置名字
int score;
};

int main(){
student s[5];
int score_, sum = 0;
cout<<"请输入5位同学的分数:"<<endl;
for(int i = 0; i < 5; i ++){
cin>>score_;
s[i].score = score_;
sum += score_;
}
//aver = sum * 0.1 / 5 ;
int highest = s[0].score;
for(int j = 1; j < 5; j ++)
if(highest<s[j].score){
int temp = highest;
highest = s[j].score;
s[j].score = temp;
}
cout<<"总和:"<<sum<<endl<<"最高:"<<highest<<endl;
return 0;
}本回答被提问者采纳
相似回答