Vending Machine Advice
Oct 4, 2011 at 4:33am UTC
Basically there are no errors, I would just like to get advice and ask, is this a good proper type of coding for a beginner? Are there any bad habits that I am doing in here?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#include <iostream>
#include <string>
using namespace std;
signed holdUP()
{ cin.sync(); cin.ignore(numeric_limits<streamsize>::max(),'\n' ); return 0; }
class user
{
public :
int moneyHolder;
};
string Line(80,'_' ), cutLines(80,'-' );
void mainHeader(void )
{ cout<<("Vending Machine Version: 1.001" )<<endl<<Line<<endl; }
int main(void )
{
user buyer;
buyer.moneyHolder = /*$*/ (float )30.00;
char menu; float water = /*$*/ 1.50; float soda = /*$*/ 2.50; float milkyway = /*$*/ 3.50;
unsigned choice;
system("Color 0a" ); //Black Background, Light Green Letters.
mainHeader();
string userName;
cout<<"Before we begin, you must enter your name." <<"\n\n\t(Hit Enter Twice When Done Writing Name)" <<endl
<<"\nEnter name:> " ;cin>>userName;
holdUP(); system("Cls" );
mainHeader();
cout<<"Type in \"M\" for male or \"F\" for female\n" ;
char gender;
cout<<"Enter Gender:> " ; cin>>gender;
holdUP(); system("Cls" );
if (gender == 'M' || gender == 'm' )
{ mainHeader();
cout<<"\t\t\t\t\t\t(You have [$" <<buyer.moneyHolder<<"] in your wallet)" <<endl;
cout<<"\nPress \"m\" for menu pop-up options:> " ; cin>>menu;
if (menu == 'M' || menu == 'm' ) //Display Menu Options.
{ cout<<"\n\t\t\t\t::MENU::" <<endl
<<"\t\t\t\t1 = Water $" <<water<<"0" <<endl
<<"\t\t\t\t2 = Soda $" <<soda<<"0" <<endl
<<"\t\t\t\t3 = Milkyway $" <<milkyway<<"0" <<endl
<<cutLines; }
do
{ cout<<"\nEnter Choice:> " ; cin>>choice;
if (choice == 1)
{ cout<<"\n\t\tYou received {Water} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 1.50<<"0] in wallet" <<endl;
buyer.moneyHolder -= 1.50; }
if (choice == 2)
{ cout<<"\n\t\tYou received {Soda} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 2.50<<"0] in wallet" <<endl;
buyer.moneyHolder -= 2.50; }
if (choice == 3)
{ cout<<"\n\t\tYou received {Milkyway} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 3.50<<"0] in wallet" <<endl;
buyer.moneyHolder -= 3.50; } } while (buyer.moneyHolder != 0); }
if (gender == 'F' || gender == 'f' )
{ mainHeader();
cout<<"\t\t\t\t\t\t(You have [$" <<buyer.moneyHolder<<"] in your purse)" <<endl;
cout<<"\nPress \"m\" for menu pop-up options:> " ; cin>>menu;
if (menu == 'M' || menu == 'm' ) //Display Menu Options.
{ cout<<"\n\t\t\t\t::MENU::" <<endl
<<"\t\t\t\t1 = Water $" <<water<<"0" <<endl
<<"\t\t\t\t2 = Soda $" <<soda<<"0" <<endl
<<"\t\t\t\t3 = Milkyway $" <<milkyway<<"0" <<endl
<<cutLines; }
do
{ cout<<"\nEnter Choice:> " ; cin>>choice;
if (choice == 1)
{ cout<<"\n\t\tYou received {Water} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 1.50<<"0] in purse" <<endl;
buyer.moneyHolder -= 1.50; }
if (choice == 2)
{ cout<<"\n\t\tYou received {Soda} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 2.50<<"0] in purse" <<endl;
buyer.moneyHolder -= 2.50; }
if (choice == 3)
{ cout<<"\n\t\tYou received {Milkyway} Enjoy!" <<endl
<<"\n\t" <<userName<<" contains [$" <<buyer.moneyHolder - 3.50<<"0] in purse" <<endl;
buyer.moneyHolder -= 3.50; } } while (buyer.moneyHolder != 0); }
holdUP(); return EXIT_SUCCESS;
}
Last edited on Oct 4, 2011 at 4:43pm UTC
Topic archived. No new replies allowed.