Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
This is just a portion of my program and I want to trap the integer inputs using while loop.

C#
cout<<"\nEnter the name : ";
while(/*while input is integer or not in character*/)
{
   //Display invalid Input!
}
cin.ignore();
cin.getline(name, 100);
Posted
Comments
Richard MacCutchan 7-Oct-14 16:43pm    
Then you need to read some input and test to see if it is an integer. You could try reading it by single character, or read a complete line and then do a test on all the characters in the line.
Sergey Alexandrovich Kryukov 7-Oct-14 18:34pm    
What do you want to achieve, exactly?
If you request for name, not only digits can be wrong. You would need to block many other characters, such as '$' (in most names :-)...
—SA
[no name] 7-Oct-14 18:39pm    
Do you really think that asking the same question over and over is going to help?

1 solution

It looks like you need to allow only alphabet input. Then the check you need for validation would be isalpha:
http://www.cplusplus.com/reference/locale/isalpha[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900