Below is my code:
char name;
bool isValid = true;
int mode;
cout << "Enter name:" << endl;
cin >> name;
do
{
cout << "Choose a mode" << endl;
cin >> mode;
switch (mode)
{
case 1:
iniCharacter (name, 110, 100, 100);
break;
case 2:
iniCharacter (name, 100, 110, 100);
break;
case 3:
iniCharacter (name, 100, 100, 110);
break;
default:
isValid = false;
cout << "Invalid mode, ";
break;
}
}while (!isValid);
But when I run the above code, the following was the output:
[output]Please enter name:
[input] test
[output] Invalid mode
[output] Invalid mode
[output] Invalid mode
[output] Invalid mode
[output] Invalid mode
...
Why did the code result in a loop even when I didn't started to input value to mode?
Shouldn't the program wait for the user to input "mode"?