Keyboard Error Handling

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

Join Date: Dec 2004
Posts: 2
Reputation: xelitex is an unknown quantity at this point 
Solved Threads: 0
xelitex xelitex is offline Offline
Newbie Poster

Keyboard Error Handling

 
0
  #1
Dec 19th, 2004
I am doing a program for school that lets the user guess the number. I am to be tested for all situations which include the user pressing a "letter" on the keyboard. I believe that I have all of the other errors handled, except for if the user enters a letter, and then the program will not execute anymore. Any help is greatly appreciated.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Keyboard Error Handling

 
0
  #2
Dec 20th, 2004
There is a standard function IsAlpha() that i have seen before in a previous post i will look it up for you
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Keyboard Error Handling

 
0
  #3
Dec 20th, 2004
i believe its in <cctype> and it returns 0 if it is numerical

alternatively there is the isdigit() function which can do all the error testing at once (it returns 0 if the character is a digit)

  1. #include <cctype>
  2. using namespace std;
  3.  
  4. char input;
  5.  
  6. cout << "Type in a number";
  7. cin >> input;
  8.  
  9. if(!isdigit(input))
  10. {
  11. // process the number
  12. }
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Keyboard Error Handling

 
0
  #4
Dec 20th, 2004
example testing code from a site i found

http://www.cse.msu.edu/~cse231/Examp.../Example04.htm
  1. /**********************************************************************
  2.  
  3.  Example #4 -- Boolean expressions
  4.  
  5. **********************************************************************/
  6.  
  7.  
  8.  
  9. #include <iostream>
  10.  
  11. #include <cctype>
  12.  
  13. using namespace std;
  14.  
  15.  
  16.  
  17. int main()
  18.  
  19. {
  20.  
  21. const bool A = true, B = false;
  22.  
  23.  
  24.  
  25. const int C = 3, D = 8;
  26.  
  27.  
  28.  
  29. const char E = 'z', F = '5';
  30.  
  31.  
  32.  
  33. cout << endl;
  34.  
  35. cout << "bool A: " << A << endl;
  36.  
  37. cout << "bool B: " << B << endl << endl;
  38.  
  39.  
  40.  
  41. cout << boolalpha;
  42.  
  43. cout << "bool A: " << A << endl;
  44.  
  45. cout << "bool B: " << B << endl << endl;
  46.  
  47.  
  48.  
  49. cout << "int C: " << C << endl;
  50.  
  51. cout << "int D: " << D << endl << endl;
  52.  
  53.  
  54.  
  55. cout << "C == D: " << (C == D) << endl;
  56.  
  57. cout << "C != D: " << (C != D) << endl;
  58.  
  59. cout << "C < 3: " << (C < 3) << endl;
  60.  
  61. cout << "C <= 3: " << (C <= 3) << endl;
  62.  
  63. cout << "C > 3: " << (C > 3) << endl;
  64.  
  65. cout << "C >= 3: " << (C >= 3) << endl << endl;
  66.  
  67.  
  68.  
  69. cout << "C >= 5 || D <= 9: " << (C >= 5 || D <= 9) << endl;
  70.  
  71. cout << "C >= 0 && D >= 4: " << (C >= 0 && D >= 4) << endl << endl;
  72.  
  73.  
  74.  
  75. cout << "C != D || C < -6: " << (C != D || C < -6) << endl;
  76.  
  77. cout << "C <= 0 && D > -6: " << (C <= 0 && D > -6) << endl << endl;
  78.  
  79.  
  80.  
  81. cout << "1 <= C && C <= 5: " << (1 <= C && C <= 5) << endl;
  82.  
  83. cout << "1 <= D && D <= 5: " << (1 <= D && D <= 5) << endl << endl;
  84.  
  85.  
  86.  
  87. cout << "char E: " << E << endl;
  88.  
  89. cout << "char F: " << F << endl << endl;
  90.  
  91.  
  92.  
  93. cout << "isalnum( E ): " << isalnum( E ) << endl;
  94.  
  95. cout << "isalpha( E ): " << isalpha( E ) << endl;
  96.  
  97. cout << "islower( E ): " << islower( E ) << endl;
  98.  
  99. cout << "isdigit( E ): " << isdigit( E ) << endl;
  100.  
  101. cout << "toupper( E ): " << static_cast<char>( toupper( E ) )
  102.  
  103. << endl << endl;
  104.  
  105.  
  106.  
  107. cout << "isalnum( F ): " << isalnum( F ) << endl;
  108.  
  109. cout << "isalpha( F ): " << isalpha( F ) << endl;
  110.  
  111. cout << "islower( F ): " << islower( F ) << endl;
  112.  
  113. cout << "isdigit( F ): " << isdigit( F ) << endl << endl;
  114.  
  115.  
  116.  
  117. return 0;
  118.  
  119. }
Last edited by 1o0oBhP; Dec 20th, 2004 at 8:50 pm. Reason: Put in code tags
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2
Reputation: xelitex is an unknown quantity at this point 
Solved Threads: 0
xelitex xelitex is offline Offline
Newbie Poster

Re: Keyboard Error Handling

 
0
  #5
Dec 21st, 2004
Thank you for all of your help everybody, it is greatly appreciated.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC