+ 1
Kindly guide me how can I check that entered variable "y" is not a number. I want to show an error msg if other than no entered
6 Réponses
+ 1
(I think) if you enter anything other than a number for int variable "y" it will contain a "0" (zero)...so with that in mind...try..
int y;
cout << "Please enter a number!" << endl;
cin >> y;
if(y == 0){
cout << "Numbers on please";
exit(EXIT_FAILURE);
}
................the rest of your code.
(although it does work, I've only checked it against a handful alphabetical characters and symbols)
0
Thanks a lot both of you sir, I will try it
0
Sir Martin Taylor , your code is for validation of variable y, in between 2 to 10. Thanks for it. It's working for validation only.
0
Sir rodwynnejones , I tried your suggestion, i.e if(y==0) , if(y >1) but not working. I found out that char s = -858993460
0
Hi..sorry for the late reply.....
I've just copied and pasted the code from my original post into my IDE and I've run it in codeplayground and it works as I thought, not sure why your getting -858993460 when you input "s".
https://code.sololearn.com/cg2mFvo4U6Q6/#cpp