3nriched

Untitled

Apr 4th, 2011
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.81 KB | None | 0 0
  1. // DrinkMachineSimulator.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6. #include <string>
  7. #include <iostream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. struct Machine
  12. {
  13.         string Name;
  14.         double Cost;
  15.         int Remaining;        
  16. };
  17.  
  18. void sodaMachine(int menuie, int NUM_SODIES,Machine sodies[]);
  19.  
  20. double totalsales = 1.00;       //machine has $1 default so it can give change
  21. int menuChoice = 0;           //declares and initializes menuChoice to 0(default).
  22.  
  23. void setSodas(int NUM_SODIES,Machine sodies[])
  24. {  
  25.         //sets the default sodas data
  26.         sodies[0].Name = "Coke Cola";sodies[0].Cost = .75;sodies[0].Remaining = 20;
  27.         sodies[1].Name = "A&W Root Beer";sodies[1].Cost = .75;sodies[1].Remaining = 20;
  28.         sodies[2].Name = "Mountain Dew";sodies[2].Cost = .75;sodies[2].Remaining = 20;
  29.         sodies[3].Name = "Sunkist Grape";sodies[3].Cost = .80;sodies[3].Remaining = 20;
  30.         sodies[4].Name = "A&W Cream Soda";sodies[4].Cost = .80;sodies[4].Remaining = 20;               
  31. }
  32. void buySoda(int menuie, int NUM_SODIES,Machine sodies[])
  33. {
  34.     double inserted, change;
  35.  
  36.    if(menuie == 1)                                                                                     //tests for option 1 selection
  37.            {
  38.                     system("cls");                                                                                  //resets screen
  39.                     cout<<"You have selected "<<sodies[0].Name<<".\n";
  40.  
  41.             if(sodies[0].Remaining = 0)
  42.                 {
  43.                     cout<<endl;
  44.                     cout<<"SOLD OUT! Please make a new selection.\n";
  45.                     system("pause");   
  46.                     system("cls");
  47.                     sodaMachine(menuie,NUM_SODIES,sodies);
  48.                 }
  49.                       cout<<"Please Enter "<<sodies[0].Cost<<".\n";
  50.                       cout<<"(Machine does not accept more than $1.00 at once.)\n";
  51.                       cout<<"Amount Entered: $";
  52.                       cin>>inserted;
  53.  
  54.                         if(inserted < 0 || inserted > 1.00)
  55.                         {
  56.                             cout<<"You have entered an incorrect amount, Please try again.\n";
  57.                             cout<<endl;
  58.                             system("pause");
  59.                             system("cls");
  60.                             sodaMachine(menuie,NUM_SODIES,sodies);
  61.                         }
  62.                             if(inserted < sodies[0].Cost)
  63.                             {
  64.                                 cout<<"I'm sorry, but you have inserted an insufficient amount.\n";
  65.                                 cout<<"***Returns change of "<<inserted<<".\n";
  66.                                 cout<<endl;
  67.                                 system("pause");
  68.                                 system("cls");
  69.                                 sodaMachine(menuie,NUM_SODIES,sodies);
  70.                             }
  71.                                 if(inserted == sodies[0].Cost)
  72.                                 {
  73.                                     totalsales += inserted;
  74.                                     inserted = 0.00;
  75.                                     sodies[0].Remaining -= 1;
  76.                                     cout<<endl;
  77.                                     cout<<"Thank you for your purchase and enjoy your drink!\n";
  78.                                     cout<<endl;
  79.                                     system("pause");
  80.                                     system("cls");
  81.                                     sodaMachine(menuie,NUM_SODIES,sodies);
  82.                                 }
  83.                                     if(inserted < 1.00 && inserted > sodies[0].Cost)
  84.                                     {
  85.                                         totalsales += inserted;
  86.                                         change = inserted - sodies[0].Cost;
  87.                                         inserted = 0.00;
  88.                                         sodies[0].Remaining -= 1;
  89.                                         cout<<endl;
  90.                                         cout<<"Your Change: $"<<change<<".\n";
  91.                                         change = 0;
  92.                                         cout<<"Thank you for your purchase and enjoy your drink!\n";
  93.                                         cout<<endl;
  94.                                         system("pause");
  95.                                         system("cls");
  96.                                         sodaMachine(menuie,NUM_SODIES,sodies);
  97.                                     }
  98.                    
  99.                     sodaMachine(menuie,NUM_SODIES,sodies);
  100.  
  101.           }
  102.     if(menuie == 2)                                                                             //tests for option 2 selection                
  103.               {
  104.                                 system("cls");                                                                          //refreshes screen                                                                                                    
  105.                        cout<<"You have selected "<<sodies[1].Name<<".\n";
  106.  
  107.                     if(sodies[1].Remaining == 0)
  108.                     {
  109.                         cout<<endl;
  110.                         cout<<"SOLD OUT! Please make a new selection.\n";
  111.                         system("pause");   
  112.                         system("cls");
  113.                             sodaMachine(menuie,NUM_SODIES,sodies);
  114.                     }
  115.  
  116.                     cout<<"Please Enter "<<sodies[1].Cost<<".\n";
  117.                     cout<<"(Machine does not accept more than $1.00 at once.)\n";
  118.                     cout<<"Amount Entered: $";
  119.                     cin>>inserted;
  120.                         if(inserted < 0 || inserted > 1.00)
  121.                         {
  122.                             cout<<"You have entered an incorrect amount, Please try again.\n";
  123.                             cout<<endl;
  124.                             system("pause");
  125.                             system("cls");
  126.                             sodaMachine(menuie,NUM_SODIES,sodies);
  127.                         }
  128.                             if(inserted < sodies[1].Cost)
  129.                             {
  130.                                 cout<<"I'm sorry, but you have inserted an insufficient amount.\n";
  131.                                 cout<<"***Returns change of "<<inserted<<".\n";
  132.                                 cout<<endl;
  133.                                 system("pause");
  134.                                 system("cls");
  135.                                 sodaMachine(menuie,NUM_SODIES,sodies);
  136.                             }
  137.                                 if(inserted == sodies[1].Cost)
  138.                                 {
  139.                                     totalsales += inserted;
  140.                                     inserted = 0.00;
  141.                                     sodies[1].Remaining -= 1;
  142.                                     cout<<endl;
  143.                                     cout<<"Thank you for your purchase and enjoy your drink!\n";
  144.                                     cout<<endl;
  145.                                     system("pause");
  146.                                     system("cls");
  147.                                     sodaMachine(menuie,NUM_SODIES,sodies);
  148.                                 }
  149.                                     if(inserted < 1.00 && inserted > sodies[1].Cost)
  150.                                     {
  151.                                         totalsales += inserted;
  152.                                         change = inserted - sodies[1].Cost;
  153.                                         inserted = 0.00;
  154.                                         sodies[1].Remaining -= 1;
  155.                                         cout<<endl;
  156.                                         cout<<"Your Change: $"<<change<<".\n";
  157.                                         change = 0;
  158.                                         cout<<"Thank you for your purchase and enjoy your drink!\n";
  159.                                         cout<<endl;
  160.                                         system("pause");
  161.                                         system("cls");
  162.                                         sodaMachine(menuie,NUM_SODIES,sodies);
  163.                                     }
  164.                    
  165.                     sodaMachine(menuie,NUM_SODIES,sodies);
  166.  
  167.               }
  168.       if(menuie == 3)                                                                     //tests for option 3 selection
  169.                  {
  170.                                         system("cls");                                                                  //refreshes screen
  171.                                                                                                                           //resets screen
  172.                        cout<<"You have selected "<<sodies[2].Name<<".\n";
  173.  
  174.                     if(sodies[2].Remaining == 0)
  175.                     {
  176.                         cout<<endl;
  177.                         cout<<"SOLD OUT! Please make a new selection.\n";
  178.                         system("pause");   
  179.                         system("cls");
  180.                             sodaMachine(menuie,NUM_SODIES,sodies);
  181.                     }
  182.  
  183.                     cout<<"Please Enter "<<sodies[2].Cost<<".\n";
  184.                     cout<<"(Machine does not accept more than $1.00 at once.)\n";
  185.                     cout<<"Amount Entered: $";
  186.                     cin>>inserted;
  187.                         if(inserted < 0 || inserted > 1.00)
  188.                         {
  189.                             cout<<"You have entered an incorrect amount, Please try again.\n";
  190.                             cout<<endl;
  191.                             system("pause");
  192.                             system("cls");
  193.                             sodaMachine(menuie,NUM_SODIES,sodies);
  194.                         }
  195.                             if(inserted < sodies[2].Cost)
  196.                             {
  197.                                 cout<<"I'm sorry, but you have inserted an insufficient amount.\n";
  198.                                 cout<<"***Returns change of "<<inserted<<".\n";
  199.                                 cout<<endl;
  200.                                 system("pause");
  201.                                 system("cls");
  202.                                 sodaMachine(menuie,NUM_SODIES,sodies);
  203.                             }
  204.                                 if(inserted == sodies[2].Cost)
  205.                                 {
  206.                                     totalsales += inserted;
  207.                                     inserted = 0.00;
  208.                                     sodies[2].Remaining -= 1;
  209.                                     cout<<endl;
  210.                                     cout<<"Thank you for your purchase and enjoy your drink!\n";
  211.                                     cout<<endl;
  212.                                     system("pause");
  213.                                     system("cls");
  214.                                     sodaMachine(menuie,NUM_SODIES,sodies);
  215.                                 }
  216.                                     if(inserted < 1.00 && inserted > sodies[2].Cost)
  217.                                     {
  218.                                         totalsales += inserted;
  219.                                         change = inserted - sodies[2].Cost;
  220.                                         inserted = 0.00;
  221.                                         sodies[2].Remaining -= 1;
  222.                                         cout<<endl;
  223.                                         cout<<"Your Change: $"<<change<<".\n";
  224.                                         change = 0;
  225.                                         cout<<"Thank you for your purchase and enjoy your drink!\n";
  226.                                         cout<<endl;
  227.                                         system("pause");
  228.                                         system("cls");
  229.                                         sodaMachine(menuie,NUM_SODIES,sodies);
  230.                                     }
  231.                    
  232.                     sodaMachine(menuie,NUM_SODIES,sodies);
  233.  
  234.                   }
  235.         if(menuie == 4)                                                             //tests for option 4 selection
  236.                    {
  237.                                                  system("cls");                                                                                  //resets screen
  238.                        cout<<"You have selected "<<sodies[3].Name<<".\n";
  239.  
  240.                     if(sodies[3].Remaining == 0)
  241.                     {
  242.                         cout<<endl;
  243.                         cout<<"SOLD OUT! Please make a new selection.\n";
  244.                         system("pause");   
  245.                         system("cls");
  246.                             sodaMachine(menuie,NUM_SODIES,sodies);
  247.                     }
  248.  
  249.                     cout<<"Please Enter "<<sodies[3].Cost<<".\n";
  250.                     cout<<"(Machine does not accept more than $1.00 at once.)\n";
  251.                     cout<<"Amount Entered: $";
  252.                     cin>>inserted;
  253.                         if(inserted < 0 || inserted > 1.00)
  254.                         {
  255.                             cout<<"You have entered an incorrect amount, Please try again.\n";
  256.                             cout<<endl;
  257.                             system("pause");
  258.                             system("cls");
  259.                             sodaMachine(menuie,NUM_SODIES,sodies);
  260.                         }
  261.                             if(inserted < sodies[3].Cost)
  262.                             {
  263.                                 cout<<"I'm sorry, but you have inserted an insufficient amount.\n";
  264.                                 cout<<"***Returns change of "<<inserted<<".\n";
  265.                                 cout<<endl;
  266.                                 system("pause");
  267.                                 system("cls");
  268.                                 sodaMachine(menuie,NUM_SODIES,sodies);
  269.                             }
  270.                                 if(inserted == sodies[3].Cost)
  271.                                 {
  272.                                     totalsales += inserted;
  273.                                     inserted = 0.00;
  274.                                     sodies[3].Remaining -= 1;
  275.                                     cout<<endl;
  276.                                     cout<<"Thank you for your purchase and enjoy your drink!\n";
  277.                                     cout<<endl;
  278.                                     system("pause");
  279.                                     system("cls");
  280.                                     sodaMachine(menuie,NUM_SODIES,sodies);
  281.                                 }
  282.                                     if(inserted < 1.00 && inserted > sodies[3].Cost)
  283.                                     {
  284.                                         totalsales += inserted;
  285.                                         change = inserted - sodies[3].Cost;
  286.                                         inserted = 0.00;
  287.                                         sodies[3].Remaining -= 1;
  288.                                         cout<<endl;
  289.                                         cout<<"Your Change: $"<<change<<".\n";
  290.                                         change = 0;
  291.                                         cout<<"Thank you for your purchase and enjoy your drink!\n";
  292.                                         cout<<endl;
  293.                                         system("pause");
  294.                                         system("cls");
  295.                                         sodaMachine(menuie,NUM_SODIES,sodies);
  296.                                     }
  297.                    
  298.                     sodaMachine(menuie,NUM_SODIES,sodies);
  299.                                                
  300.  
  301.                  }
  302.          if(menuie == 5)                                                     //tests for option 5 selection
  303.                   {
  304.                           system("cls");                                                                                  //resets screen
  305.                        cout<<"You have selected "<<sodies[4].Name<<".\n";
  306.  
  307.                     if(sodies[4].Remaining == 0)
  308.                     {
  309.                         cout<<endl;
  310.                         cout<<"SOLD OUT! Please make a new selection.\n";
  311.                         system("pause");   
  312.                         system("cls");
  313.                             sodaMachine(menuie,NUM_SODIES,sodies);
  314.                     }
  315.  
  316.                     cout<<"Please Enter $"<<sodies[4].Cost<<".\n";
  317.                     cout<<"(Machine does not accept more than $1.00 at once.)\n";
  318.                     cout<<"Amount Entered: $";
  319.                     cin>>inserted;
  320.                         if(inserted < 0 || inserted > 1.00)
  321.                         {
  322.                             cout<<"You have entered an incorrect amount, Please try again.\n";
  323.                             cout<<endl;
  324.                             system("pause");
  325.                             system("cls");
  326.                             sodaMachine(menuie,NUM_SODIES,sodies);
  327.                         }
  328.                             if(inserted < sodies[4].Cost)
  329.                             {
  330.                                 cout<<"I'm sorry, but you have inserted an insufficient amount.\n";
  331.                                 cout<<"***Returns change of "<<inserted<<".\n";
  332.                                 cout<<endl;
  333.                                 system("pause");
  334.                                 system("cls");
  335.                                 sodaMachine(menuie,NUM_SODIES,sodies);
  336.                             }
  337.                                 if(inserted == sodies[4].Cost)
  338.                                 {
  339.                                     totalsales += inserted;
  340.                                     inserted = 0.00;
  341.                                     sodies[4].Remaining -= 1;
  342.                                     cout<<endl;
  343.                                     cout<<"Thank you for your purchase and enjoy your drink!\n";
  344.                                     cout<<endl;
  345.                                     system("pause");
  346.                                     system("cls");
  347.                                     sodaMachine(menuie,NUM_SODIES,sodies);
  348.                                 }
  349.                                     if(inserted < 1.00 && inserted > sodies[4].Cost)
  350.                                     {
  351.                                         totalsales += inserted;
  352.                                         change =+ (inserted - sodies[4].Cost);
  353.                                         inserted = 0.00;
  354.                                         sodies[4].Remaining -= 1;
  355.                                         cout<<endl;
  356.                                         cout<<"Your Change: $"<<change<<".\n";
  357.                                         change = 0;
  358.                                         cout<<"Thank you for your purchase and enjoy your drink!\n";
  359.                                         cout<<endl;
  360.                                         system("pause");
  361.                                         system("cls");
  362.                                         sodaMachine(menuie,NUM_SODIES,sodies);
  363.                                     }
  364.  
  365.                     sodaMachine(menuie,NUM_SODIES,sodies);                                              
  366.                       }
  367. }
  368.  
  369. void sodaMachine(int menuie, int NUM_SODIES,Machine sodies[])
  370. {
  371.     cout<<endl;cout<<endl;
  372.         do                                            //loops the menu - handles out of range integer input
  373.         {
  374.         cout<<endl;cout<<endl;cout<<endl;
  375.        
  376.                 cout<<"\t\t\t>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
  377.                 cout<<"\t\t\t^      Choose a Refreshment      v\n";                        ///////////////////
  378.                 cout<<"\t\t\t^      --------------------      v\n";                        //  Sweet Menu   //
  379.                 cout<<"\t\t\t^      1)  Coke Cola             v\n";                        ///////////////////
  380.                 cout<<"\t\t\t^      2)  A&A Root Beer         v\n";
  381.                 cout<<"\t\t\t^      3)  Mountain Dew          v\n";
  382.                 cout<<"\t\t\t^      4)  Sinkist Grape         v\n";
  383.                 cout<<"\t\t\t^      5)  A&W Cream Soda        v\n";
  384.                 cout<<"\t\t\t^      6)  Exit Machine          v\n";
  385.                 cout<<"\t\t\t<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
  386.                 cout<<endl;cout<<endl;                                                                          //clean fill
  387.  
  388.                
  389.                     cin>>menuie;                                                        //assigns user selection to variable
  390.                    
  391.                    
  392.                     if(menuie >= 1 && menuie <= 5)
  393.                     {
  394.                        
  395.                        buySoda(menuie, NUM_SODIES, sodies);
  396.                     }
  397.  
  398.                     if(menuie == 6)
  399.                     {
  400.                         system("cls");
  401.                         cout<<endl;
  402.                         cout<<"Total Sales of Machine: $"<<totalsales<<".\n";
  403.                         cout<<endl;
  404.                         system("pause");
  405.                         exit (0);
  406.                     }
  407.                     system("cls");
  408.         }while(menuie < 1 || menuie > 6);                                                       //loop handler for menuchoices not available
  409.  
  410.  
  411.     sodaMachine(menuie,NUM_SODIES,sodies);
  412.  
  413. }
  414.  
  415. int _tmain(int argc, _TCHAR* argv[])
  416. {
  417.         system("Color 17");
  418.        
  419.         const int NUM_SODAS = 5;   //number of sodas
  420.         Machine sodas[NUM_SODAS];   //array of structures
  421.  
  422.         setSodas(NUM_SODAS,sodas);   //calls the setSodas function and loads machine with soda persay..
  423.  
  424.         cout<<"\t\t\tThe Soda Machine Simulator 200!!!\n";
  425.        
  426.         sodaMachine(menuChoice,NUM_SODAS,sodas);
  427.  
  428.  
  429.     return 0;
  430. }
Advertisement
Add Comment
Please, Sign In to add comment