| | |
Keyboard Error Handling
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
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)
alternatively there is the isdigit() function which can do all the error testing at once (it returns 0 if the character is a digit)
C++ Syntax (Toggle Plain Text)
#include <cctype> using namespace std; char input; cout << "Type in a number"; cin >> input; if(!isdigit(input)) { // process the number }
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
example testing code from a site i found
http://www.cse.msu.edu/~cse231/Examp.../Example04.htm
http://www.cse.msu.edu/~cse231/Examp.../Example04.htm
C++ Syntax (Toggle Plain Text)
/********************************************************************** Example #4 -- Boolean expressions **********************************************************************/ #include <iostream> #include <cctype> using namespace std; int main() { const bool A = true, B = false; const int C = 3, D = 8; const char E = 'z', F = '5'; cout << endl; cout << "bool A: " << A << endl; cout << "bool B: " << B << endl << endl; cout << boolalpha; cout << "bool A: " << A << endl; cout << "bool B: " << B << endl << endl; cout << "int C: " << C << endl; cout << "int D: " << D << endl << endl; cout << "C == D: " << (C == D) << endl; cout << "C != D: " << (C != D) << endl; cout << "C < 3: " << (C < 3) << endl; cout << "C <= 3: " << (C <= 3) << endl; cout << "C > 3: " << (C > 3) << endl; cout << "C >= 3: " << (C >= 3) << endl << endl; cout << "C >= 5 || D <= 9: " << (C >= 5 || D <= 9) << endl; cout << "C >= 0 && D >= 4: " << (C >= 0 && D >= 4) << endl << endl; cout << "C != D || C < -6: " << (C != D || C < -6) << endl; cout << "C <= 0 && D > -6: " << (C <= 0 && D > -6) << endl << endl; cout << "1 <= C && C <= 5: " << (1 <= C && C <= 5) << endl; cout << "1 <= D && D <= 5: " << (1 <= D && D <= 5) << endl << endl; cout << "char E: " << E << endl; cout << "char F: " << F << endl << endl; cout << "isalnum( E ): " << isalnum( E ) << endl; cout << "isalpha( E ): " << isalpha( E ) << endl; cout << "islower( E ): " << islower( E ) << endl; cout << "isdigit( E ): " << isdigit( E ) << endl; cout << "toupper( E ): " << static_cast<char>( toupper( E ) ) << endl << endl; cout << "isalnum( F ): " << isalnum( F ) << endl; cout << "isalpha( F ): " << isalpha( F ) << endl; cout << "islower( F ): " << islower( F ) << endl; cout << "isdigit( F ): " << isdigit( F ) << endl << endl; return 0; }
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:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Similar Threads
- keyboard error or no keyboard present at bootup (Troubleshooting Dead Machines)
- Keyboard Error Or No Keyboard Present (Motherboards, CPUs and RAM)
- Keyboard error or no keyboard present (USB Devices and other Peripherals)
- strange keyboard error (Troubleshooting Dead Machines)
- Keyboard error or no keyboard present (USB Devices and other Peripherals)
Other Threads in the C++ Forum
- Previous Thread: error C2447: missing function header (old-style formal list?), what does this mean?!
- Next Thread: How do I start an exe file from C++
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





