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
#include <iostream>
usingnamespace 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;
}
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:
#include <iostream>
usingnamespace 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: