0
爲什麼此代碼總是返回'false'並且即使在輸入數字時也會激活goto?誰能幫幫我嗎?謝謝!爲什麼程序總是返回'false'?
char userValue = '4';
auto h = true;
tryAgain:
std::cout << "Please type a digit: ";
std::cin >> userValue;
switch (userValue) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
h = true;
default:
h = false;
}
switch (h) {
case true:
std::cout << "This character is a digit.";
case false:
std::cout << "Wrong! Try again!" << std::endl;
goto tryAgain;
}
鏘有一個[警示選項](http://coliru.stacked-crooked.com/a/558934c7b81f965d)。 – chris
爲每個案例添加中斷 – MaxDevelop
您已經解決了這個特定問題。一般的解決方案是使用調試器,它可以讓你看到發生了什麼。 –