Thread: Issue with if statement + a general question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    2

    Issue with if statement + a general question

    Hello! I just started working on my first proper C++ project, and have finally run into an issue I haven't been able to solve myself. I've spent a few hours thinking about it and fiddling around with it while searching to see if I could find a comparable example, but no dice, so here I am.

    The issue is here:
    Code:
    //Get player's gender
    string playerGenderFunct()
    {
        enum playerGender{MALE, FEMALE, NEUTRAL};
        cout << "What pronouns do you prefer?" << endl;
        cout << "Select from the following:" << endl;
        cout << "Male" << endl;
        cout << "Female" << endl;
        cout << "Neutral (ze/hir)" << endl;
        map <string, playerGender> playerGenderMap;
        playerGenderMap["Male"] = MALE;
        playerGenderMap["Female"] = FEMALE;
        playerGenderMap["Neutral"] = NEUTRAL;
        string selectedPlayerGender;
        cin >> selectedPlayerGender;
        playerGender playerPronouns = playerGenderMap[selectedPlayerGender];
        if (selectedPlayerGender != "Male" || selectedPlayerGender != "Female" || selectedPlayerGender != "Neutral")
        {
            cout << "That is not a supported option, please re-enter." << endl;
            cin >> selectedPlayerGender;
        }
        cout << "You prefer " << selectedPlayerGender << " pronouns.  Is this correct? If so, hit 'y'." << endl;
        char playerGenderCheck = 'n';
        cin >> playerGenderCheck;
        do
        {
            if (playerGenderCheck != 'y')
            {
                cout << "Please re-enter your gender." << endl;
                cin >> selectedPlayerGender;
                if (selectedPlayerGender != "Male" || selectedPlayerGender != "Female" || selectedPlayerGender != "Neutral")
                {
                    cout << "That is not a supported option, please re-enter." << endl;
                    cin >> selectedPlayerGender;
                }
                cout << "Are " << selectedPlayerGender << " pronouns your preference? If so, hit 'y'." << endl;
                cin >> playerGenderCheck;
            }
        } while (playerGenderCheck != 'y');
        cout << "\n\n";
    
        return selectedPlayerGender;
    }
    What it is meant to do is ask a question with preset options, check to see if it fits one of the options, and if not ask for it to be re-entered. However it currently has an issue where no matter what is entered the first time, it says it's incorrect. I'm figuring that the issue is with the first batch of this code.

    Code:
        if (selectedPlayerGender != "Male" || selectedPlayerGender != "Female" || selectedPlayerGender != "Neutral")
        {
            cout << "That is not a supported option, please re-enter." << endl;
            cin >> selectedPlayerGender;
        }
    I've tried a few different things, from moving it around a bit (since the second time that code shows up it appears to be working fine?) to changing it to do and while loops and sticking continue in there...nothing has worked. So I'd really love some suggestions on things to try to get it to work, since this appears several times in the program. Alternatively if you have a suggestion of a better way to accomplish this I'd be open to that too.

    I'm also just trying to get into good habits, so if you see something else blaringly awkward about the code feel free to let me know.

    Nevermind on the following question, I finally figured out what it was called.

    I'm also wondering how you you would go about attaching a script (plot/speech, not code) to a program, as I'm assuming it generally isn't written straight into the source code? I've been having some trouble searching for an answer to this since script tends to mean code when talking about programming. (If there is some more appropriate term for what I'm trying to figure out you could just tell me that and I can probably find what I'm looking for on my own if you don't feel like typing up a long response.)

    Thank you!
    Last edited by Rumtehk_uh; 08-21-2013 at 01:30 PM. Reason: Answered question, specified C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. general question
    By ingeniousreader in forum C Programming
    Replies: 4
    Last Post: 05-21-2012, 09:59 AM
  2. While Statement Issue.
    By mcertini in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2011, 12:34 PM
  3. Just a general question;
    By fthmdg in forum C++ Programming
    Replies: 7
    Last Post: 04-09-2010, 04:14 PM
  4. issue with switch statement
    By bluetxxth in forum C Programming
    Replies: 14
    Last Post: 02-24-2010, 10:01 AM
  5. General GUI question in C
    By Music_Man in forum Game Programming
    Replies: 3
    Last Post: 11-16-2001, 11:45 AM