讨论 / 今天刚交的struct.新手测试,.写的复杂了
LeeHW 2016-12-05 19:16:43
点我顶贴 收藏 删除
#include<iostream>

using namespace std;

int money(int ave,int pin,char ganbu,char xibu,int lunwen)

{

int total_money = 0;

if (ave>80 && lunwen >= 1)

{

total_money += 8000;

}

if (ave>85 && pin>80)

{

total_money += 4000;

}

if (ave>90)

{

total_money += 2000;

}

if (ave>85 && xibu == 'Y')

{

total_money += 1000;

}

if (pin>80 && ganbu == 'Y')

{

total_money += 850;

}

return total_money;

}

struct student

{

char name[20];

int ave;

int pin;

char ganbu;

char xibu;

int lunwen;

};

int main()

{

int num,tmp,q,total=0;

student NUM[100];

int totalMoney[100];

cin >> num;

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

{

cin >> NUM[i].name>>NUM[i].ave>>NUM[i].pin>>NUM[i].ganbu>>NUM[i].xibu>>NUM[i].lunwen;

totalMoney[i] = money(NUM[i].ave, NUM[i].pin, NUM[i].ganbu, NUM[i].xibu, NUM[i].lunwen);

total = total + totalMoney[i];

}

tmp = totalMoney[0];

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

{

if (totalMoney[i]>tmp)

{

tmp = totalMoney[i];

q = i;

}

}

cout << NUM[q].name << '\n' << totalMoney[q]<<'\n'<<total<<endl;

return 0;

}

查看更多回复
提交回复