Why won't my code go to the second option I want avaliable?

Trying to make a super basic proof of concept game with my very limited knowledge, I want to type 1 to go north, 2 to go south, but only the north option will display no matter what. I had it working before, tried something else, removed it and now this is happening

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

using namespace std;

int main()
{
    int Variable;
    int exit;

    cout<<"You wake up in a forest, surrounded by trees. You feel that the forest is impassable in any direction other than north and south. Type enter to continue.\n";
    cin.get ();
    cout<<"Type 1 to go north, 2 to go south\n";
    cin>> Variable;
    if (Variable = 1)
        {
            cout<<"You walk north, and enter into an impassable maze, slowly starving to death, and being forced to drink your own blood for sustainence. You slowly die. You lose. And you suck.\n";
        }
    else if (Variable = 2)
        {
            cout<<"you travel south, and are met by a large black fellow. He stabs you in the chest, and you die, slowly gargling your last words, but nobody hears them. You lose, and you suck.\n";
            cin.get ();
            cout<<"Type anything to exit";
        }
    cin>> exit;
    return 1;

}
Hi @josephbraun99,
if (Variable = 1)

else if (Variable = 2)


you are using the
= assignment operator
instead of == relational operator
"Equal to"
for instance:

1
2
3
4
5
6
7
8
9
10
11
12
int var=1;

if(var==1) //if var is equal to 1
{
    //do something
    cout<<"Option 1"<<endl;
   
}else if(var==2)// else if var is equal to 2..
{
    //do something else
    cout<<"Option 2"<<endl; 
}


Topic archived. No new replies allowed.