Character handling problem! (isdigit)

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 49
Reputation: dexter1984 is an unknown quantity at this point 
Solved Threads: 2
dexter1984 dexter1984 is offline Offline
Light Poster

Character handling problem! (isdigit)

 
0
  #1
Aug 27th, 2008
  1. void choiceSelect()
  2. {
  3. int choice;
  4. char exitconfirm[100];
  5. printmenu();
  6. cin >> choice;
  7.  
  8. if (isdigit(choice))
  9. {
  10. if (choice == 7)
  11. {
  12. cout << "Exiting program. Enter yes to confirm.\n";
  13. cin.ignore();
  14. cin.getline (exitconfirm, 100, '\n');
  15. if (strcmp ("yes", exitconfirm) == 0)
  16. {
  17. exit (1);
  18. }
  19. else
  20. {
  21. choiceSelect();
  22. }
  23. }
  24.  
  25.  
  26. while (choice != 7)
  27. {
  28. if (choice == 1)
  29. cout << "1";
  30. else if (choice == 2)
  31. cout << "2";
  32. else if (choice == 3)
  33. cout << "3";
  34. else if (choice == 4)
  35. cout << "4";
  36. else if (choice == 5)
  37. cout << "5";
  38. else if (choice == 6)
  39. cout << "6";
  40. else
  41. choiceSelect();
  42. }
  43. }
  44.  
  45. else
  46. {
  47. cout <<"error!!!";
  48. cin.ignore();
  49. choiceSelect();
  50. }
  51. }

Hi, I need some help with my assignment yet again. This time, it's just a simple recursive loop that I can't get working.

I've done most parts but I can't figure out why the "isdigit" isn't working. I want the program to detect if the user inputs anything other than numbers.

If I understand correctly,
if (isdigit(choice))
if choice = numbers, it'll run the program since it's true. However, it doesn't, Instead it runs the else part.

Can anyone point me in the right direction. Appreciate the help
Last edited by dexter1984; Aug 27th, 2008 at 12:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Character handling problem! (isdigit)

 
1
  #2
Aug 27th, 2008
Doesn't isdigit expect a char?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 49
Reputation: dexter1984 is an unknown quantity at this point 
Solved Threads: 2
dexter1984 dexter1984 is offline Offline
Light Poster

Re: Character handling problem! (isdigit)

 
0
  #3
Aug 27th, 2008
!!!
Aaaa I see, forgot about the little int choice at the top.
Thanks!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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