0

i want to write some code that can input only number or only character ?
plz help me ???

5
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by jonsca
0

Use if-else structure to check your conditional statement and apply loop for prompting the user to enter valid input.

0

why not use cin object as a test condition? That way it can get type mismatch and it won't write data to that type and we can easily get rid of bad input and ask user to reenter with proper data. Would this be a bad approach?

0

@Crutoy : Please show an example code. :P
I'm not getting exactly what you're telling him to do. So please give an example...
Thanks.

0

i never know that we can use cin as condition but like @Crutory i don't understand also

0

why not use cin object as a test condition? That way it can get type mismatch and it won't write data to that type and we can easily get rid of bad input and ask user to reenter with proper data. Would this be a bad approach?

That will work, too. OP, you'll need to use either the .fail() or the .good() method of the input stream for that (see http://www.cplusplus.com/reference/iostream/ios/good/ etc)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.