0
코드가 있습니다.잘못된 입력을 입력하면 루프가 무한 루프에 들어갑니다.
bool exitRunner=true;
unsigned short int choiceNum=0;
int main(int argc, const char * argv[]) {
while(exitRunner)
{
cout << "Please specifiy the choice that you want to proceed \n";
cout <<"1: Encryption \v 2: Decryption \v 3: Exit \n";
cin >> choiceNum;
switch (choiceNum)
{
case 1:
{
//Encryption
break;
}
case 2:
{
//Decryption
break;
}
case 3:
{
exitRunner=false;
break;
}
default:
{
cout << "Invalid Input \n";
}
}
}
하지만 문자와 같은 잘못된 입력을 입력 한 후, 프로그램이 무한 루프에 들어갑니다, 그것은 다시 모든 입력을 요구하지 않습니다.
출력은 다음과 같습니다.
Please specifiy the choice that you want to proceed
1: Encryption 2: Decryption 3: Exit
Invalid Input
Please specifiy the choice that you want to proceed
1: Encryption 2: Decryption 3: Exit
Invalid Input
Please specifiy the choice that you want to proceed
1: Encryption 2: Decryption 3: Exit
Invalid Input
실제로 올바른 입력 (1,2,3)을 입력하더라도 가끔 무한 루프에 다시 입력됩니다. 그건 그렇고, 나는 $ choiceNum에 대한 입력에 대해 이야기하고있다.
코드에있는 내용은 무엇이며 어떻게 수정할 수 있습니까? 또는 무엇이 문제를 일으키는 지 알 수 있습니까?