hi,
could anyone give me examples of 2 fuction please.
1) to force 'enter only numbers' not letters
2) to force 'enter only letters' not numbers
thanks.
Printable View
hi,
could anyone give me examples of 2 fuction please.
1) to force 'enter only numbers' not letters
2) to force 'enter only letters' not numbers
thanks.
Code:void ENTERANUMBER(int &num) {
cout << "ENTER A NUMBER AND ONLY A NUMBER!!!!";
cin >> num;
}
void ENTERALETTER(char &let) {
cout << "ENTER A LETTER AND ONLY A LETTER!!!!";
cin >> let;
}
alrite if u incorporate a bit of warning in those functions they will work well,like:-
suppose someone enters a number when he should enter a letter ,the function should give out an error message and should ask him to enter a letter again,this should go on till he enters a letter,now thats a " force letter only " function.
Regardless, he'd have to know how to clear cin after the stream fails.
Your easiest bet would be to take it in as a character, regardless, compare it's ASCII range to the range that letters are in or numbers are in. If it matches, keep it, if it doesn't, ask again.