#include <iostream>
using namespace std;
int main()
{
int score;
char grade;
cout << "Enter your score:" << endl;
cin >> score;
if (score >= 90)
grade = 'a';
if (score >= 80)
grade = 'b';
if (score >= 70)
grade = 'c';
if (score >= 60)
grade = 'd';
else
grade = 'f';
cout << grade << endl;
switch (grade) {
case 'a':
cout << "Good job" << endl;
break;
case 'c':
cout << "Fair job" << endl;
break;
case 'f':
cout << "Failure" << endl;
break;
default:
cout << "invalid" << endl;
}
cin.get();
return 0;
}
爲什麼它給了我默認開關的情況下,當我進入95
時,我應該得到情況下switch語句C++幫助
你爲什麼要把數字轉換成一個字母,然後把這個字母轉換成更長的措辭描述?跳過'switch'並在你的第一個'if'中打印(當然你修好之後)。過度併發症是我們最糟糕的詛咒,反對它! – Blindy
因爲'case'd':'缺少你注意到正在輸出哪個等級? – AJG85
您是否在開關啓動之前檢查了等級的輸出是否返回** a ** – punit