User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,429 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,913 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 3841 | Replies: 10
Reply
Join Date: Sep 2004
Posts: 6,059
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: error checking of user input

  #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):
bool is_valid_name ( char name[] )
{
  for ( int i = 0; name[i] != '\0'; i++ )
  {
    if ( !isalpha ( name[i] )
      return false;
  }

  return true;
}

void game::get_name()
{
  cout << "Enter your name? ";
  cin.getline(player_name, 50);

  while(!is_valid_name(player_name))
  {
    cout << "You must enter a name and not a digit!" << "\n""\n";

    clear_screen();

    cout << "Enter your name? ";
    cin.getline(player_name, 50);
  }
}
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC