-7

I'm trying to make a little game, and I'm a beginner.

The problem is the parts with the ifs and the else, where it says "Lady" and "Sir".

#include <iostream>
#include <string>


using namespace std; 

int main()
{
    string playerName;
    int age;
    int playerGender;

    cout << "Are you a Lady or a Sir?" << endl;
    cin >> playerGender;

    if (playerGender = Lady)
    {
    cout << "So you're a girl. " << endl;
    }
    else if (playerGender = Sir)
    {
    cout << "So you're a boy." << endl;
    }
    cout << "What is your name " << playerGender << "?" << endl;
    cin >> playerName;

    cout << "What is your age?" << playerName << endl;
    cin >> age;

    if (age <= 10)
    {
    cout << "You're too young " << playerName << "! " << endl;
    }
    else if (age >= 11)
    {
    cout << "You are old enough to play" << playerName << ". " << endl;

That's what I have, I don't know whats wrong. Help please!

ibizaman
  • 3,053
  • 1
  • 23
  • 34

1 Answers1

1

When you perform the following:

std::cin >> playerGender;

You are retrieving a number from the user. You are then assigning that number to your playerGender with the following:

if (playerGender = Lady)

You're only using a single =, which assigns the value that's in Lady to playerGender. You probably mean to write == which will compare the value of playerGender and Lady.

I can't tell what Lady and Sir are, but for your purposes you will need to ensure they are an int:

const int Lady = 0, Sir = 1;

Or an enum:

enum genders { Lady = 0, Sir = 1 };

Now you can make the following comparison:

if (playerGender == Lady)
{
}
else if (playerGender == Sir)
{
}
Tas
  • 7,023
  • 3
  • 36
  • 51