Noob mistake

Umm yeah I have probably the most rookie mistake been learning c++ for a 2 weeks now need help with this please help. When you enter red and enter New York nothing shows up. Its really frustrating I tried putting a else statement but its not working. I tried putting in (Bobby == "Alabama" || Bobby == "New York")
{ string cheese = "Welcome to " + Bobby + "!";
cout << " Congraulations" << cheese << endl;
but thats not working either help me..

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 #include <iostream>
#include <string>
using namespace std;

int main()
{
     string  name;
    cout << "Please enter your name" << endl;
    cin >> name;

//Introduction to the game
string greetings ="Hello  " + name + "! ";

cout << greetings << "Welcome to our game" << endl;

string choose;
cout << "Choose if you wanna be (blue or red)" << endl;
cin >> choose;
if (choose == "red")
{
    cout << "You are a red character" << endl;
}
{
     string Bobby;
    cout << "Do you wanna go to (Alabama or New York)" << endl;
cin >> Bobby;
 if (Bobby == "Alabama")
  {

    string cheese = " Welcome to  " + Bobby + "!";
    cout << "Congraulations" << cheese << endl;

  }

{
   if (Bobby == "New York")
    {
       string cheese2 = " Welcome to  " + Bobby + "!";
    cout << "Congraulations" << cheese2 << endl;
    }



}

 if (choose == "blue") //Blue statement
{
    cout << "You are a blue character" << endl;
}
}
}
The way you use code blocks is very odd. There are else statements :P You should probably use those.


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string  name;
    cout << "Please enter your name" << endl;
    cin >> name;

    //Introduction to the game
    string greetings ="Hello  " + name + "! ";

    cout << greetings << "Welcome to our game" << endl;

    string choose;
    cout << "Choose if you wanna be (blue or red)" << endl;
    cin >> choose;
    if (choose == "red")
    {
        cout << "You are a red character" << endl;
    }
    {
        string Bobby;
        cout << "Do you wanna go to (Alabama or New York)" << endl;
        cin >> Bobby;
        if (Bobby == "Alabama")
        {

            string cheese = " Welcome to  " + Bobby + "!";
            cout << "Congraulations" << cheese << endl;

        }

        {
            if (Bobby == "New York")
            {
                string cheese2 = " Welcome to  " + Bobby + "!";
                 cout << "Congraulations" << cheese2 << endl;
            }



        }

        if (choose == "blue") //Blue statement
        {
            cout << "You are a blue character" << endl;
        }
    }
}


The reason new york does not work is because with cin >> by default stops reading when it hits a white space. You probably want to use getline.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 #include <iostream>
#include <string>
using namespace std;

int main()
{
    string  name;
    cout << "Please enter your name" << endl;
    cin >> name;

    //Introduction to the game
    string greetings ="Hello  " + name + "! ";

    cout << greetings << "Welcome to our game" << endl;

    string choose;
    cout << "Choose if you wanna be (blue or red)" << endl;
    cin >> choose;
    if (choose == "red")
    {
        cout << "You are a red character" << endl;
    }
    else if(choose == "blue")
    {
        cout << "You are a blue character" << endl;
    }
    
    string Bobby;
    cout << "Do you wanna go to (Alabama or New York)" << endl;
    getline(cin >> ws, Bobby);
    if (Bobby == "Alabama")
    {

        string cheese = " Welcome to  " + Bobby + "!";
        cout << "Congraulations" << cheese << endl;

    }

    else if (Bobby == "New York")
    {
        string cheese2 = " Welcome to  " + Bobby + "!";
         cout << "Congraulations" << cheese2 << endl;
    }
    
}
Please enter your name
Fred
Hello  Fred! Welcome to our game
Choose if you wanna be (blue or red)
red
You are a red character
Do you wanna go to (Alabama or New York)
New York
Congraulations Welcome to  New York!
Thanks i am a rookie 2 weeks in now I know all the basics just need to know when to use them..
Topic archived. No new replies allowed.