2019-01-24

Hyeonu_Chun·2021년 6월 21일
0

HW5

#include <iostream>
#include <iomanip>
using namespace std;

void my_flush();

int main() {
	char str[10];
	const char *name[6] = { "이름","국어","영어" ,"수학","총점","평균" };
	int score[3];
	cout << "이름 : ";
	cin.getline(str, sizeof(str));
	cout << "세 과목의 점수 : ";
	cin >> score[0] >> score [1] >> score[2];
	while ((cin.fail()) || (cin.get() != '\n')) {
		my_flush();
		cout << "정확한 점수를 입력하세요" << endl << endl << "세 과목의 점수 : ";
		cin >> score[0] >> score[1] >> score[2];
	}
	int sum = score[0] + score[1] + score[2];
	cout << "\t\t=====< 성적표 >=====" << endl << "====================================================" << endl;
	for (auto t : name) {
		cout << setw(8) << t;
	}
	cout << endl << "====================================================" << endl;
	cout << setw(8) << str;
	for (auto t : score) {
		cout << setw(8) << t;
	}
	cout << setw(8) << sum << setw(8) << fixed << setprecision(2) << sum / 3.0;
	return 0;
}

void my_flush() {
	cin.clear();
	while (cin.get() != '\n');
	return;
}
profile
Stay hungry, stay foolish

0개의 댓글