我的问题是我不知道如何插入一个规则,如果用户在字符串上输入了一个数字,它会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;