我剛剛開始使用C++,我遇到了一個錯誤。它告訴我,我有一個「其他」沒有以前的「如果」,但我做到了。我檢查了代碼的情況,它看起來基本上就像我從中學習的網站的例子,它只是在所有cout之後有不同的句子,所以我不知道什麼是錯的。任何幫助都感激不盡。簡單的C++錯誤,「否則沒有以前如果」
int main()
{
int iOud;
cout<<"Type in your age: ";
cin >> iOud; //"a variable for the person's age
cin.ignore();
if (iOud < 20);{
cout<< "A message\n";
}
else if (iOud > 40) {
cout << "A message\n";
}
else {
cout << "A message\n";
}
cin.get();
}
'switch/case'在這裏效果不好,因爲他比較了一系列值(使用'<' and '>')而不是尋找離散值(使用'==')。 – Sean
是的,我在一般意義上講的是更多,但感謝清除。 – McBooley