Need some quick help with this code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need some quick help with this code

Hi, I'm trying to put what little i've learned so far to use.

As I said before my goal is to make a text-based rpg...so i decied to write up a room description and see if i could make it switch back and forth between rooms based on the user's input:


#include

int main()

{

cout << "You are standing in the middle of a large chamber.
"<br>
"Obvious Exits: North, South
";

enum Directions {North=1, South=2};

char x;

cin >> x;

char N = 1;

char S = 2;

if (x = N)

cout << "Display North
";<br>
if (x = S)

cout << "Display South
"; <br>
return 0;

}


The only problem is that no matter what you push (N or S) it will write Display North

Display South.


Does anyone have any suggestions as to how i could make it just write Display North when i enter N

and Display South when i enter S?


Penance




Comments

  • .

    .

    .

    : if (x = N)

    : cout << "Display North
    ";<br>
    : if (x = S)

    : cout << "Display South
    "; <p>
    You're conditions for your if statement are incorrect, should be like this:

    if (x == N) { ... }

    if (x == S) { ... }


    The operator '=' and '==' are two different things.


    ~Abbott


    URL:http://www.Geocities.com/SiliconValley/Heights/5082



  • int main()

    {

    cout << "You are standing in the middle of a large chamber.
    "<br>
    "Obvious Exits: North, South
    ";


    char x;

    cin >> x;


    if (x == 'N')

    cout << "Display North
    ";<br>
    if (x == 'S')

    cout << "Display South
    "; <br>
    return 0;

    }



    greetings


Sign In or Register to comment.