# Nub Code Questions

• 10-25-2004
Zeusbwr
Nub Code Questions
Ya i know this code is horribly jumbled, iv been dinkin around with it. Anyway how do you check if a variable is eqal(ornot) to a letter? Also, how do you check say like if a variable is a number, or a letter, or caps, ect.
like isnum, isalhpa, !isnum, ect.

Code:

```        do         {                int input;             char inputl;             cout<<"Which dice do you wish to keep? (Note: Use the dice number, not the number the dice rolled.)\n: ";             cin>>input;             while((input < 1) || (input > 6)){                 cout<<"Invalid Number, You Rolled 6 Dice. Please choose a die to keep.\n";                 cin>>input;             }             keep[x] = input;             cout<<"Is that all you wish to keep? 'y/n'\n";             cin>>inputl;             while((inputl != n) && (inputl != y)){                 cout<<"Invalid.\nIs that all you wish to keep? 'y/n'\n";                 cin>>inputl;             }         }while(input != n);         cout<<"Do you wish to Roll Again? y/n\n";         cin>>inputl;         while((inputl != n) && (inputl != y)){             cout<<"Invalid.\nDo you wish to Roll Again? y/n\n";             cin>>inputl;         }```
Error:
Quote:

142 `n' undeclared (first use this function)
142 `y' undeclared (first use this function)
and if i remember right, the bold part is the problem. But theres a couple sections that would cause errors under the 'n' is undeclared thing.

I assume my compiler is looking at "n" and "y" and saying there variables that have not been declared. But how then do i compare a variable to a letter? (char)# ?(where # is the ASCII number for your desired letter)?

Thanks :)
• 10-25-2004
7smurfs
You can use the strcmp() function ( I think that's the right function), and compare the user input to a string. If it returns true, than do whatever, if false, do what ever.
• 10-25-2004
prog-bman
<< !! Posting Code? Read this First !! >>
Well you kinda tried so make sure you end your tags with a /
• 10-25-2004
jlou
To indicate that something is a char and not a variable name, use single quotes.
Code:

`while((inputl != 'n') && (inputl != 'y')){`
• 10-25-2004
Zeusbwr
oops sorry, simple mis type. Check all my past posts i havent missed one yet, no need for FLAMING BIG RED TEXT lol :p.

jlou:
Thanks! :)