Can anyone give advice about my codes?

#include <cstdlib>
#include <iostream>

using namespace std;



int main(int argc, char *argv[])
{
char choice;



int cups;
int supplies[4];
start:

cout<< "Welcome to your lemonade stand!!";
cout<< endl;
cout<< "What would you want to do?";
cout<< endl;
cout<< endl<<"Check Supplies: Press S"<<endl;
cout<< "Check Orders: Press O"<<endl;

cin>> choice;


switch(choice)
{
case 'S':
case 's':
int item;
cout<< endl<<"Choose item: [Enter number]"<<endl;
cout<< "Ice: 1"<<endl;
cout<< "Lemons: 2"<<endl;
cout<< "Sugar: 3"<<endl;
cout<< "Cups: 4"<<endl;
cin>> item;

switch(item)
{
case 1:
int cubes;
int ice;
ice=0;
int icecube;

if (ice == 0)
{
cout<< endl<<"You don't have any ice cubes, would you like to order? [1=yes/2=no]"<<endl;
cin>> icecube;

if(icecube==1)
{
cout<<endl<<"How many ice cubes?"<<endl;
cin >> cubes;
supplies[0] = cubes;
cout<< supplies[0]<<" ice cubes ordered.";
}
if(icecube==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<ice<<" ice cubes left."<<endl;
}
goto start;
break;

case 2:
int lemon;
int lemons;
lemon=0;
int none;

if (lemon == 0)
{
cout<< endl<<"You don't have any lemons, would you like to order? [1=yes/2=no]"<<endl;
cin>> none;

if(none==1)
{
cout<<endl<<"How many lemons?"<<endl;
cin >> lemons;
supplies[1] = lemons;
cout<< supplies[1]<<" lemons ordered.";
}
if(none==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<lemon<<" lemons left."<<endl;
}


break;
case 3:
int shuga;
int sugar;
shuga=0;
int zugar;

if (shuga == 0)
{
cout<< endl<<"You don't have any sugar, would you like to order? [1=yes/2=no]"<<endl;
cin>> zugar;

if(zugar==1)
{
cout<<endl<<"How many packs of sugar?"<<endl;
cin >> shuga;
supplies[2] = shuga;
cout<< supplies[2]<<" packs of sugar ordered.";
}
if(zugar==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<shuga<<" packs of sugar left."<<endl;
}


break;
}

break;



















default:
cout<<"Wrong choice."<<endl;
cout<< "Choose again."<<endl;
system("pause");
system("cls");
goto start;
break;
}









system("PAUSE");
return EXIT_SUCCESS;

}






---------->> These are what I've coded so far, the problem is, I don't know what to do next.. Do you have suggestions?? My codes aren't that good yet, I'm still revising it as of now.. BTW, how can I implement Classes in my codes?
Also, when the program starts again, the values inputted for the items become 0 again, like for the ice, when I order 20 cubes, it becomes 0 again when it starts from the top.
Last edited on
Well, there are two things that jump out at me immediately about your code that you should not be doing. You're using a goto statement and return EXIT_SUCCESS rather than return 0;
Your variable naming convention is not good.

Consider someone else trying to understand your code and seeing three variables named sugar, shuga, and zugar, the latter two of which seem simply to be word plays on "sugar". What do these variables hold? From their names, it sounds like they are the same thing.

Also, lemon and lemons.

Also, cubes, ice, and icecube.


#include <cstdlib>
#include <iostream>

using namespace std;



int main(int argc, char *argv[])
{
char choice;
int supplies[4];
start:

cout<< "Welcome to your lemonade stand!!";
cout<< endl;
cout<< "What would you want to do?";
cout<< endl;
cout<< endl<<"Check Supplies: Press S"<<endl;
cout<< "Check Orders: Press O"<<endl;

cin>> choice;


switch(choice)
{
case 'S':
case 's':
int item;
cout<< endl<<"Choose item: [Enter number]"<<endl;
cout<< "Ice: 1"<<endl;
cout<< "Lemons: 2"<<endl;
cout<< "Sugar: 3"<<endl;
cout<< "Cups: 4"<<endl;
cin>> item;

switch(item)
{
case 1:
int ice;
ice=0;
int order;

if (ice == 0)
{
cout<< endl<<"You don't have any ice cubes, would you like to order? [1=yes/2=no]"<<endl;
cin>> order;

if(order==1)
{
cout<<endl<<"How many ice cubes?"<<endl;
cin >> supplies[0] ;
cout<< supplies[0]<<" ice cubes ordered.";
}
if(order==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<ice<<" ice cubes left."<<endl;
}
goto start;
break;

case 2:
int lemon;
lemon=0;


if (lemon == 0)
{
cout<< endl<<"You don't have any lemons, would you like to order? [1=yes/2=no]"<<endl;
cin>> order;

if(order==1)
{
cout<<endl<<"How many lemons?"<<endl;
cin >> supplies[1];

cout<< supplies[1]<<" lemons ordered.";
}
if(order==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<lemon<<" lemons left."<<endl;
}
goto start;

break;
case 3:
int sugar;
sugar=0;


if (sugar == 0)
{
cout<< endl<<"You don't have any sugar, would you like to order? [1=yes/2=no]"<<endl;
cin>> order;

if(order==1)
{
cout<<endl<<"How many packs of sugar?"<<endl;
cin >> supplies[2];

cout<< supplies[2]<<" packs of sugar ordered.";
}
if(order==2)
{
cout<<"Okay!"<<endl;
}
}
else
{
cout<< "You have "<<sugar<<" packs of sugar left."<<endl;
}
goto start;

break;
}

break;



default:
cout<<"Wrong choice."<<endl;
cout<< "Choose again."<<endl;
system("pause");
system("cls");
goto start;
break;
}



system("PAUSE");
return 0;

}




Okay, I've edited my codes.. This is what I have so far.. But there's an error, why does it keep looping when I enter a wrong choice??
What can I now do next??
Thanks for the replies earlier..
Your code is very unstructured and you are using goto! don't do that because you don't need it, go to is almost never used in programming, replace it with a while loop, the rest divide it into functions... How long do you program?
Last edited on
Don't use goto as outsider said. It makes it almost impossible to read your code.

Always indent your code. It makes it much more readable.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char choice;
int supplies[4];
double total=0;
start:


cout<< "Welcome to your lemonade stand!!";
cout<< endl;
cout<< "What would you want to do?";
cout<< endl;
cout<< endl<<"Check Supplies: Press S"<<endl;
cout<< "Check Orders: Press O"<<endl<<endl;

cin>> choice;


if (choice =='S')
{
int item;
int Nitem;
cout<<"Choose item: [Enter number]"<<endl;
cout<< "Ice: 1"<<endl;
cout<< "Lemons: 2"<<endl;
cout<< "Sugar: 3"<<endl;
cout<< "Cups: 4"<<endl;
cin>> item;

int totali;
if (item==1)
{
int i=2;
cout<<"You Have choosen Ice";
cout<<"Please enter No. of Amount You want: ";
cin>>Nitem;
totali=i*Nitem;
}
else if (item==2)
{
int l=10;
cout<<"You Have choosen Lemon";
cout<<"Please enter No. of Amount You want: ";
cin>>Nitem;
totali=l*Nitem;
}
else if (item==3)
{
int s=20;
cout<<"You Have choosen Sugar";
cout<<"Please enter No. of Amount You want: ";
cin>>Nitem;
totali=s*Nitem;
}
else if (item==4)
{
int c=15;
cout<<"You Have choosen Cups";
cout<<"Please enter No. of Amount You want: ";
cin>>Nitem;
totali=c*Nitem;
}
else
{
cout<<"Invalid Input";
}
total=totali;
}
else if (choice=='O')
{
cout<<"Your Total Orders are:"<<total;
}
else
cout<<"Sorry Your choices are S and 0 only";


system("PAUSE");
return 0;
}




Here's my new set of codes.. Can anyone see problems about it? How do I use classes for this kind of program? And how can I make it store the values that the user sets?
Topic archived. No new replies allowed.