C++ All Int are valid for the if statement | if(choice == 1)
I've got some probably simple questions: why is every Integer accepted as a valid input in the if statement and why is the code following the if statement not being executed #include #include int main(){ int choice; std::cout
I've got some probably simple questions:
why is every Integer accepted as a valid input in the if statement
and why is the code following the if statement not being executed
#include
#include
int main(){
int choice;
std::cout << "Enter the number 1" <<'\n';
while (!(std::cin >> choice)){
if(choice == 1) {
std::cout << "good" << '\n';
break;
}
else{
std::cout << "bad" << '\n';
std::cin.clear();
std::cin.ignore(std::numeric_limits::max(), '\n');
std::cout << "enter the number 1!"<< '\n';
}
}
return 0;
}