Nub Code Questions

This is a discussion on Nub Code Questions within the C++ Programming forums, part of the General Programming Boards category; Ya i know this code is horribly jumbled, iv been dinkin around with it. Anyway how do you check if ...

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    Question 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:
    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
    Last edited by Zeusbwr; 10-25-2004 at 09:30 PM.
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    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.
    To code is divine

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    << !! Posting Code? Read this First !! >>
    Well you kinda tried so make sure you end your tags with a /
    Woop?

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    To indicate that something is a char and not a variable name, use single quotes.
    Code:
    while((inputl != 'n') && (inputl != 'y')){

  5. #5
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    oops sorry, simple mis type. Check all my past posts i havent missed one yet, no need for FLAMING BIG RED TEXT lol .


    jlou:
    Thanks!
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C interview questions
    By natrajdreams in forum C Programming
    Replies: 7
    Last Post: 12-12-2010, 11:40 AM
  2. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  3. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21