2019-01-24
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;
}
Reference
この問題について(2019-01-24), 我々は、より多くの情報をここで見つけました
https://velog.io/@hyeonu_chun/2019-01-24
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
#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;
}
Reference
この問題について(2019-01-24), 我々は、より多くの情報をここで見つけました https://velog.io/@hyeonu_chun/2019-01-24テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol