Isaac87
2014. 7. 23. 12:57
구조체 배열 + 반복문 + 조건문
#include <iostream> using namespace std;
typedef struct { int kor; int math; int eng; char grade; } Student;
int main() { Student stu[5];
for(int i=0; i<5; i++) { int total = 0; cin >> stu[i].kor >> stu[i].math >> stu[i].eng; total = stu[i].kor + stu[i].math + stu[i].eng; if(total >= 270 && total <= 300) stu[i].grade = 'A'; else if(total >= 240 && total < 270) stu[i].grade = 'B'; else if(total >= 210 && total < 240) stu[i].grade = 'C'; else stu[i].grade = 'D'; }
for(int i=0; i<5; i++) { cout << "--------------------------" << endl; cout << i << "번째 학생" << endl; cout << "국어 점수 : " << stu[i].kor << endl; cout << "수학 점수 : " << stu[i].math << endl; cout << "영어 점수 : " << stu[i].eng << endl; cout << "등급 : " << stu[i].grade << endl; } return 0; } |