I'm writing a program with an outer loop and an inner loop. When you select what size pizza you want, you'll be taken to an inner loop to pick toppings. I'm stuck trying to figure out how to use a loop that incorporates my first choice, and then adds whatever toppings I choose after each selection. Can I use a method as my inner loop that accepts my pizza size choice as its parameter?
Thanks in advance, and here's what I have right now:
#include <iostream>
usingnamespace std;
class pizza
{
public:
int size;
};
int main()
{
pizza value;
char response;
do
{
cout << "What size pizza? \n\n";
cout << " 1 for small \n 2 for medium \n 3 for large\n Q to quit\n";
cin >> response;
if (response == 1 || response == 2 || response == 3)
{
value.size = response;
if (response = 1)
//inner menu loop - small pizza
elseif (response = 2)
//inner menu loop - medium pizza
elseif (response = 3)
//inner menu loop - large pizza
}
elseif (response == 'q' || response == 'Q')
break;
}
while (not sure what my while will be yet...)
}
#include <iostream>
usingnamespace std;
class pizza
{
public:
int size;
};
int main()
{
pizza value;
char response;
do
{
cout << "What size pizza? \n\n";
cout << " 1 for small \n 2 for medium \n 3 for large\n Q to quit\n";
cin >> response;
if (response == 1 || response == 2 || response == 3)
{
value.size = response;
innerLoop(value.size);
}
elseif (response == 'q' || response == 'Q')
break;
else
//I would suggest handling errors
}
while (not sure what my while will be yet...)
}
So this would assume the inner loop for each size of pizza has the same logic. If you need any help from here, let me know
#include <iostream>
usingnamespace std;
class pizza
{
private:
int size;
vector<string> toppingList; //or you could use an array, if you know the max toppings...
//or a good assumption for max toppings.
public:
pizza() //default contructor
{
this.size = 0;
}
void addToppings()
{
string topping;
int numToppings;
cout << "How Many toppings would you like?\n";
cin >> numToppings;
for (i = 0; i < numToppings; i++)
{
cout << "Enter topping number " << i << ":\n";
cin >> topping;
this.toppingList.push_back(topping);
}
}
};
int main()
{
string response;
vector<pizza> order;
pizza currentPizza;
do
{
cout << "What size pizza? \n\n";
cout << " 1 for small \n 2 for medium \n 3 for large\n Q to quit\n";
cin >> response;
if (response == 1 || response == 2 || response == 3)
{
currentPizza.size = response;
currentPizza.addToppings();
order.push_back(currentPizza); //put current pizza onto orderList
}
elseif (response == 'Q' || response == 'Q')
{
break;
}
else
{
//I would suggest handling errors, i.e user enters something other than 1,2,3, q, Q
}
}
while (response != 'q' || response != 'Q')
}
Thanks so much for the advice, Nick Schuck! I'm taking it all in and trying to determine how to best incorporate what you've shared.
I do have a question though: I will be using an array instead of a vector, but it's my first program using an array, so I'm not sure how to do it. How would one take input from the user and grab the corresponding object from the array?
Ps. I'm working on the errors, too. I was trying to keep the code short.