Problem with script stopping the execution

For some reason after I do the command of if (Aisle) and typing 'Aisle 1' it just finishes the execution and passes over everything else in the code. AddToCart function isn't finished please no spoilers except how to fix my problem. This is still a work in progress
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
53
54
55
56
57
#include <iostream>

using namespace std;

int main()
{
    string Input;
    string Aisle;
    string Section;
    string Item;
    int Amount;
    int MaltoMeal = 5;
    int Oatmeal = 2;
    int CreamofWheat = 3;

    cout << "Welcome to the Shop n' Go cornerstore!" << endl;
    cout << "To browse our wares type 'StartShopping'." << endl;
    cin >> Input;
    if (Input == "StartShopping")
    {
        cout << "\nAisle 1: Hot Cereal\n         Cold Cereal\n         Jarred items" << endl;
        cin >> Aisle;
        if (Aisle == "Aisle 1")
        {
            cout << "On this aisle we have: Hot Cereal, Cold Cereal, and Jarred items." << endl;
            cout << "You walk down Aisle 1 and stare at our wares." << endl;
            cout << "Choose your section to look at." << endl;
            cin >> Section;
            if (Section == "Hot Cereal")
            {
                cout << "We currently have: " << MaltoMeal << " boxes of MaltoMeal, " << Oatmeal << " boxes of Oatmeal, and " << CreamofWheat << " boxes of CreamofWheat." << endl;
                cout << "To purchase one of these items type AddToCart or type NewAisle to find a new aisle to look on and NewSection to look at different sections of the Aisle." << endl;
                cin >> Item;
                if (Item == "AddToCart")
                {
                    cout << "Would you like to add MaltoMeal, Oatmeal, or CreamofWheat." << endl;
                    cin >> Input;
                    if (Input == "MaltoMeal")
                    {
                        cout << "How much would you like to purchase?" << endl;
                        cin >> Amount;
                        if (Amount > 6)
                        {
                            cout << "Sorry, we do not have that much MaltoMeal at the time." << endl;
                        }
                        else
                        {
                            cout << "Adding " << Amount << " boxes of MaltoMeal to your cart. . ." << endl;

                        }
                    }
                }
            }
        }
    }
    return 0;
}
Last edited on
Please help
Simple problem-solving.

Here is what you should have thought:

Hmmm, that's funny, I wonder why that happens. I'm sure I'm entering the right value for Aisle. How can I check? I know, I can add a line to output Aisle before the comparison, like this:

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
53
54
55
56
57
58
#include <iostream>

using namespace std;

int main()
{
    string Input;
    string Aisle;
    string Section;
    string Item;
    int Amount;
    int MaltoMeal = 5;
    int Oatmeal = 2;
    int CreamofWheat = 3;

    cout << "Welcome to the Shop n' Go cornerstore!" << endl;
    cout << "To browse our wares type 'StartShopping'." << endl;
    cin >> Input;
    if (Input == "StartShopping")
    {
        cout << "\nAisle 1: Hot Cereal\n         Cold Cereal\n         Jarred items" << endl;
        cin >> Aisle;
          cout << "Aisle is: " << Aisle << endl;
        if (Aisle == "Aisle 1")
        {
            cout << "On this aisle we have: Hot Cereal, Cold Cereal, and Jarred items." << endl;
            cout << "You walk down Aisle 1 and stare at our wares." << endl;
            cout << "Choose your section to look at." << endl;
            cin >> Section;
            if (Section == "Hot Cereal")
            {
                cout << "We currently have: " << MaltoMeal << " boxes of MaltoMeal, " << Oatmeal << " boxes of Oatmeal, and " << CreamofWheat << " boxes of CreamofWheat." << endl;
                cout << "To purchase one of these items type AddToCart or type NewAisle to find a new aisle to look on and NewSection to look at different sections of the Aisle." << endl;
                cin >> Item;
                if (Item == "AddToCart")
                {
                    cout << "Would you like to add MaltoMeal, Oatmeal, or CreamofWheat." << endl;
                    cin >> Input;
                    if (Input == "MaltoMeal")
                    {
                        cout << "How much would you like to purchase?" << endl;
                        cin >> Amount;
                        if (Amount > 6)
                        {
                            cout << "Sorry, we do not have that much MaltoMeal at the time." << endl;
                        }
                        else
                        {
                            cout << "Adding " << Amount << " boxes of MaltoMeal to your cart. . ." << endl;

                        }
                    }
                }
            }
        }
    }
    return 0;
}


Here is a sample run:

Welcome to the Shop n' Go cornerstore!
To browse our wares type 'StartShopping'.
StartShopping

Aisle 1: Hot Cereal
         Cold Cereal
         Jarred items
Aisle 1
Aisle is Aisle


Well that's odd. I typed in Aisle 1, but the value of the variable was just Aisle. Where did the 1 go?

I'll experiment.


More sample output from experimenting:

Welcome to the Shop n' Go cornerstore!
To browse our wares type 'StartShopping'.
StartShopping

Aisle 1: Hot Cereal
         Cold Cereal
         Jarred items
Aisle1 1
Aisle is Aisle1


Hmmm. Looks like anythign after the space doesn't get read in. I'll double check that hypothesis using google:

http://www.google.com/search?btnG=1&pws=0&q=cin+stops+reading+at+space

Oh yes, it's a common problem, and there are some solutions. Seems that cin stops reading at the first space by default. Well, that's that solved.
Lol fail, I knew about that common problem. Brain fart ;) thanks anyway
Topic archived. No new replies allowed.