patterncppMinor
Lemonade stand menu program
Viewed 0 times
lemonadestandprogrammenu
Problem
This is an assignment given in my C++ programming class. I have one main menu with four other menus branching out from it. I would like to make my code as clutter-free as I can, so please review this code and give me feedback.
```
#include
#include
#include
#include
using namespace std;
struct Selection_Choices
{
string choice1;
string choice2;
string choice3;
};
Selection_Choices lemonade [3];
Selection_Choices shirts [2];
Selection_Choices cookies [3];
int menu_1= 1;
int menu_2= 1;
int menu_3= 1;
double running_Total = 0;
void lemonade_Menu ();
void cookie_Menu ();
void shirt_Menu ();
void purchase_Total();
void purchase_order( double );
void menu_check();
void main ()
{
int menu;
cout >menu;
switch(menu)
{
case 1 :
lemonade_Menu();
break;
case 2 :
cookie_Menu();
break;
case 3 :
shirt_Menu ();
break;
case 4 :
purchase_Total();
break;
case 5 :
exit(0);
break;
default :
cout ::max(),'\n');
cin.get();
main();
}
system ("pause");
}
void lemonade_Menu ()
{
menu_check();
double price = 0 ;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_1++;
price = .50;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
lemonade_Menu();
}
}
void cookie_Menu ()
{
menu_check();
double price = .75;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_2++;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
cookie_Menu();
}
}
void shirt_Menu ()
{
menu_check();
double price = 0;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_3++;
price = 4.00;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
shirt_Menu();
}
}
void purchase_order( double current_order)
{
int menu;
cout >menu;
switch(menu)
{
case 1 :
if ( running_Total == 0 )
{
running_Total = current_order;
}
else
{
running_Total = running_Total + current_order;
}
main();
break;
case 2 :
if ( running_Total == 0 )
{
running_Total = current_order;
}
else
{
running_Total = running_Total + current_order;
}
purchase_Total();
break;
default :
cout ::max(),'\n');
cin.get();
purchase
```
#include
#include
#include
#include
using namespace std;
struct Selection_Choices
{
string choice1;
string choice2;
string choice3;
};
Selection_Choices lemonade [3];
Selection_Choices shirts [2];
Selection_Choices cookies [3];
int menu_1= 1;
int menu_2= 1;
int menu_3= 1;
double running_Total = 0;
void lemonade_Menu ();
void cookie_Menu ();
void shirt_Menu ();
void purchase_Total();
void purchase_order( double );
void menu_check();
void main ()
{
int menu;
cout >menu;
switch(menu)
{
case 1 :
lemonade_Menu();
break;
case 2 :
cookie_Menu();
break;
case 3 :
shirt_Menu ();
break;
case 4 :
purchase_Total();
break;
case 5 :
exit(0);
break;
default :
cout ::max(),'\n');
cin.get();
main();
}
system ("pause");
}
void lemonade_Menu ()
{
menu_check();
double price = 0 ;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_1++;
price = .50;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
lemonade_Menu();
}
}
void cookie_Menu ()
{
menu_check();
double price = .75;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_2++;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
cookie_Menu();
}
}
void shirt_Menu ()
{
menu_check();
double price = 0;
int menu;
cout >menu;
switch(menu)
{
case 1 :
menu_3++;
price = 4.00;
for ( int index = 0 ; index ::max(),'\n');
cin.get();
shirt_Menu();
}
}
void purchase_order( double current_order)
{
int menu;
cout >menu;
switch(menu)
{
case 1 :
if ( running_Total == 0 )
{
running_Total = current_order;
}
else
{
running_Total = running_Total + current_order;
}
main();
break;
case 2 :
if ( running_Total == 0 )
{
running_Total = current_order;
}
else
{
running_Total = running_Total + current_order;
}
purchase_Total();
break;
default :
cout ::max(),'\n');
cin.get();
purchase
Solution
Here's a few things I noted:
-
Don't have
-
The C++ standard states that you should use
-
The comments already stated this, but your indentation needs to improve. Right now this program is nearly unreadable.
-
Why do you need so many newline characters in this line? And why are you yelling at me?
I personally think that makes the output look ugly and unprofessional.
-
I see a few calls to
-
Consider using the
What if you forget the type of
Note that this is from the C++11 standards.
-
The post-incrementation
-
Don't have
using namespace std; in your code. It's almost universally considered a bad practice.-
The C++ standard states that you should use
int main() and not void main(). Bjarne Stroustrup (a creator of C++) stated that this isn't even C++ (or even C!). I'm surprised you could even get this to work, my compiler won't even let me do that.-
The comments already stated this, but your indentation needs to improve. Right now this program is nearly unreadable.
-
Why do you need so many newline characters in this line? And why are you yelling at me?
cout <<"\n\n\n\n\n\n\n\n\n\n \t EACH ITEM HAS A PURCHASE LIMIT DUE TO POPULAR DEMAND \n" ;I personally think that makes the output look ugly and unprofessional.
-
I see a few calls to
main() in your code. Use loops in their place instead.-
Consider using the
auto type for some of your variables. For example:for ( int index = 0 ; index < menu_3 ; index++)What if you forget the type of
menu_3? Or what if it is some long and complex type name to specify so that index matches it? Here is a better way IMO:for (auto index = 0; index < menu_3; ++index)Note that this is from the C++11 standards.
-
The post-incrementation
i++ needs to create a temporary variable to store the original value of i, then performs the incrementation and returns the temporary variable. The pre-incrementation ++i doesn't create a temporary variable. Sure, any decent optimization setting should be able to optimize this away when the object is something simple like an int, but remember that the ++-operators are overloaded in more complicated classes like iterators. Therefore, I would always use the pre-incrementation in a for loop.Code Snippets
cout <<"\n\n\n\n\n\n\n\n\n\n \t EACH ITEM HAS A PURCHASE LIMIT DUE TO POPULAR DEMAND \n" ;for ( int index = 0 ; index < menu_3 ; index++)for (auto index = 0; index < menu_3; ++index)Context
StackExchange Code Review Q#63277, answer score: 8
Revisions (0)
No revisions yet.