very beginner:only take int values from cin

Hi this is my first question and am an absolute beginner
i wanted to display a message if input is not int value.i am making a text guessing game but it worked well but when i type in 0 it displayed the error message
so my question is can i just do it this way?(is this valid)
1
2
3
4
5
int Input;
char Not_Input;
cin>>Input;
if(Input==Not_Input)
cout<<"only numbers are allowed";
You are trying to compare a character (Not_Input) to an integer (Input).
Is there a specific reason why?
What error message did it give you?

You need to initialize Not_Input or it will just be some garbage value and you won't be able to predict the behavior of your program.

My compiler (Microsoft Visual Studio) will give me a "uninitialized local variable used" error, and will refuse to even compile.
Characters are integers can be compared, but you need to know how they work.

Yes, it is valid, but you may not get the behavior you are expecting.
Topic archived. No new replies allowed.