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
您已经解决了这个特定问题。一般的解决方案是使用调试器,它可以让你看到发生了什么。 –