Thread: choice error

  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105

    choice error

    I'm having trouble with two nearly identical blocks of code in my program:

    Code:
    do
        {
                cout<<"What is your charater's name?\n";
                cin.ignore();
                getline( cin, yourname);
                do
                {
                   cout<<"Your character's name is "<<yourname<<". Is that okay?\n";
                   getline( cin, choice);
                } while (toupper(choice[0]) != 'y' && toupper(choice[0]) != 'n');
                if (toupper(choice[0] == 'n'))
                {
                       ok=false;
                }
                else
                {
                    ok=true;
                }
        }while (ok==false);
    It stays at the prompt without advancing past it, no matter what garbage is typed in.
    Hatman Approves!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    How is toupper(anything) going to equal 'y'?

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    It's code I got off of a question I asked a couple of months ago. http://cboard.cprogramming.com/showthread.php?t=106347

    It was to equate any input beginning with 'y' to 'y'. The code didn't act up until recently.
    Hatman Approves!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Except you did an extremely poor job of it. 'Y' is an uppercase letter; 'y' is not.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    I intended for all input to be in lowercase. This code worked until recently, and both places where it was placed stopped working.

    EDIT: I'm pretty sure I didn't change the check to lowercase, as the other place the code stopped working is the (until recently) woking version of the save function in the other thread.
    Last edited by DarkAlex; 11-10-2008 at 10:39 PM.
    Hatman Approves!

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you want lowercase, then you should use tolower, not toupper.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    And try to actually understand what you are typing. Don't just blindly type the code like a monkey.

  8. #8
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    That fixed it, thank you. That makes me feel stupid.
    Hatman Approves!

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Quote Originally Posted by DarkAlex View Post
    That fixed it, thank you. That makes me feel stupid.
    But you have to admit it was funny.
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  10. #10
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Yep, I do have to admit that. I also noticed that I had made this error in other areas of the program that would not have been good there. I also noticed that I had used == instead of = in three places.
    Hatman Approves!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM