Name: Anonymous 2011-06-02 0:40
Hello, I need help with this one assignment. I'm not sure how to go any further with it. Pleas help, thank you.
assignment:
A lemonade stand needs to purchase supplies in order to do business. This stand has money (double), and keeps a stock of lemons (int), cups (int), sugar (int) and ice (int). Write a function that takes these five variables as parameters by reference and allows the owner of the stand to purchase new stock. The function should allow the owner to specify which item they wish to purchase, how many of the items they wish to purchase and should loop until they choose to quit.
my code:
void LemonadeStand(double& money, int& lemons, int& cups, int& sugar, int& ice)
{
char keepBuying;
int choice;
while(keepBuying=='y' || money >0)
{
cout<<"welcome to the lemonade inventory center, you have $100.00 to spend."<<endl;
cout<<"What would you like to buy?(all $1 each)"<<endl;
cout<<"1.Sugar"<<endl;
cout<<"2.Ice"<<endl;
cout<<"3.Cups"<<endl;
cout<<"4.Lemons"<<endl;
switch (choice)
{
case 1 :cout<<"How many bags of sugar do you want?"<<endl;
cin>>sugar;
money == money-(sugar*1);
case 2 :cout<<"How many boxes of lemons do you want?"<<endl;
cin>>lemons;
money == money-(lemons*1);
case 3 :cout<<"How many trays of ice do you want?"<<endl;
cin>>ice;
money == money-(ice*1);
case 4 :cout<<"How many cups do you want?"<<endl;
cin>>cups;
money == money-(cups*1);
}
cout<<"would you like to keep buying?"<<endl;
cin>>choice;
if(keepBuying='n')
{
cout<<"Goodbye!"<<endl;
}
if(money==0)
{
cout<<"Sorry, you do not enough money to buy anything"<<endl;
}
}
}
is this good? I don't think I followed the assignment correctly.
Can someone do it their way so I can see the proper way to do it?
assignment:
A lemonade stand needs to purchase supplies in order to do business. This stand has money (double), and keeps a stock of lemons (int), cups (int), sugar (int) and ice (int). Write a function that takes these five variables as parameters by reference and allows the owner of the stand to purchase new stock. The function should allow the owner to specify which item they wish to purchase, how many of the items they wish to purchase and should loop until they choose to quit.
my code:
void LemonadeStand(double& money, int& lemons, int& cups, int& sugar, int& ice)
{
char keepBuying;
int choice;
while(keepBuying=='y' || money >0)
{
cout<<"welcome to the lemonade inventory center, you have $100.00 to spend."<<endl;
cout<<"What would you like to buy?(all $1 each)"<<endl;
cout<<"1.Sugar"<<endl;
cout<<"2.Ice"<<endl;
cout<<"3.Cups"<<endl;
cout<<"4.Lemons"<<endl;
switch (choice)
{
case 1 :cout<<"How many bags of sugar do you want?"<<endl;
cin>>sugar;
money == money-(sugar*1);
case 2 :cout<<"How many boxes of lemons do you want?"<<endl;
cin>>lemons;
money == money-(lemons*1);
case 3 :cout<<"How many trays of ice do you want?"<<endl;
cin>>ice;
money == money-(ice*1);
case 4 :cout<<"How many cups do you want?"<<endl;
cin>>cups;
money == money-(cups*1);
}
cout<<"would you like to keep buying?"<<endl;
cin>>choice;
if(keepBuying='n')
{
cout<<"Goodbye!"<<endl;
}
if(money==0)
{
cout<<"Sorry, you do not enough money to buy anything"<<endl;
}
}
}
is this good? I don't think I followed the assignment correctly.
Can someone do it their way so I can see the proper way to do it?