error checking of user input

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error checking of user input

 
0
  #11
Apr 18th, 2005
And here I thought you were asking for something odd. All of the examples I first gave you do exactly what you want. But since you seem exceptionally helpless, I'll solve your problem for you (just this once though):
  1. bool is_valid_name ( char name[] )
  2. {
  3. for ( int i = 0; name[i] != '\0'; i++ )
  4. {
  5. if ( !isalpha ( name[i] )
  6. return false;
  7. }
  8.  
  9. return true;
  10. }
  11.  
  12. void game::get_name()
  13. {
  14. cout << "Enter your name? ";
  15. cin.getline(player_name, 50);
  16.  
  17. while(!is_valid_name(player_name))
  18. {
  19. cout << "You must enter a name and not a digit!" << "\n""\n";
  20.  
  21. clear_screen();
  22.  
  23. cout << "Enter your name? ";
  24. cin.getline(player_name, 50);
  25. }
  26. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC