How can I get the program below to reject all characters except numbers and these symbols (-, =, +, *, /, %)
Printable View
How can I get the program below to reject all characters except numbers and these symbols (-, =, +, *, /, %)
You need to write your own input function using get
something like this:
Code:do {
a = cin.get()
if ( a == desiredchar )
input += a
} while ( inputting )
A switch and case statement may be easier to use.
Code:bool ValidChar(char C)
{
if((C >= '0') && (C <= '9')) return true;
if(C == '-') return true;
if(C == '=') return true;
if(C == '+') return true;
if(C == '*') return true;
if(C == '/') return true;
if(C == '%') return true;
return false;
}
Or even
:)Code:bool ValidChar(char C)
{
return strchr( "0123456789-+*/%=", C ) != NULL;
}
Where do I put the bool statement? (I'm a newbie.)