i'm making simple program to show "True" if user input 'z' and show "False" if user input anything else. However, the problem is when user input more than a character, such as when user input 'zz' the output is
True
Input : True
and when user input such as 'zs' which should be wrong, the output is
True
Input : Wrong
Here's my code
#include <iostream>
using namespace std;
int main()
{
char input;
cout << "Check input" << endl;
while(true){
cout << "Input : ";
cin >> input;
if(input=='z'){
cout << "True" << endl;
} else {
cout << "Wrong" << endl;
}
}
return 0;
}
I wonder if there are ways to prevent this without change variable type to string?
I use CodeBlocks 16.04 (MinGW) with GNU GCC Compiler on Windows 10 x64