cout
ここでの問題は、ユーザーが文字列に数字を入力した場合、ユーザーが成績に文字列/文字を入力した場合と同じように、それが有効ではないという警告が表示されるルールを挿入する方法がわからないことです。どのように?私はそれを試してきましたが、式は機能しません。
int x, cstotal = 100, extotal = 150;
double scorecs, exscore, labtotala, labtotalb, total;
string mystr = "";
cout << "Compute for: " << "\n" << "1. Laboratory Grade " << "\n" << "2. Lecture Grade" << "\n" << "3. Exit" << "\n";
cout << "Please enter a number: ";
cin >> x;
switch (x) {
case 1:
cout << "Compute for laboratory grade." << "\n";
cout << "Enter Student Name: ";
cin >> mystr;
cout << "Good day, " << mystr << " . Please provide the following grades: " << "\n";
cout << "CS Score: ";
cin >> scorecs;
cout << "Exam Score: ";
cin >> exscore;
labtotala = scorecs / cstotal * 0.6;
labtotalb = exscore / extotal * 0.4;
total = labtotala + labtotalb;
cout << "Your Laboratory Grade is " << total * 100 << "\n";
system("pause");
break;
case 2:
cout << "Compute for lecture grade." << "\n";
cout << "Enter Student Name: ";
cin >> mystr;
cout << "Good day, " << mystr << " . Please provide the following grades: " << "\n";
cout << "CS Score: ";
cin >> scorecs;
cout << "Exam Score: ";
cin >> exscore;
labtotala = scorecs / cstotal * 0.7;
labtotalb = exscore / extotal * 0.3;
total = labtotala + labtotalb;
cout << "Your Lecture Grade is " << total * 100 << "\n";
system("pause");
break;