fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5. int SIZE = 5;
  6. struct soda
  7. {
  8. string name;
  9. float cost;
  10. int number;
  11.  
  12. };
  13. void printMenu();
  14.  
  15. soda allSodas[5] = {
  16. {"Cola ", 0.75, 20 },
  17. {"Root Beer ", 0.75, 20 },
  18. {"Lemon-Lime", 0.75, 20 },
  19. {"Grape Soda", 0.80, 20 },
  20. {"Cream Soda", 0.80, 20 }
  21. };
  22.  
  23.  
  24. int main() {
  25. int userDecision;
  26. float moneyInserted;
  27. cout << fixed << showpoint << setprecision(2);
  28. printMenu();
  29. cout << "Pick a drink or quit program by pressing number" << endl;
  30. cout << "Cola (1), Root Beer (2), Lemon-Lime (3)" << endl;
  31. cout << "Grape Soda (4), Cream Soda (5), Quit (6)" << endl;
  32. cin >> userDecision;
  33. if(userDecision == 6)
  34. cout << "exit program" << endl;
  35.  
  36. if(userDecision > 0 && userDecision < 6)
  37. {
  38. cout << "Enter money inserted: " << endl;
  39. cin >> moneyInserted;
  40. cout << "Change " << moneyInserted - allSodas[userDecision].cost << endl;
  41. allSodas[userDecision].number = allSodas[userDecision].number - 1;
  42. printMenu();
  43.  
  44. }
  45. if(userDecision < 0 || userDecision > 6)
  46. cout << "Try again, must be a number 1 through 6" << endl;
  47.  
  48. return 0;
  49. }
  50. void printMenu()
  51. { cout << "Soda price inventory" << endl;
  52. for(int i = 0; i < SIZE; i++)
  53. {
  54. cout << allSodas[i].name << setw(10);
  55. cout << allSodas[i].cost << setw(10) << allSodas[i].number << endl;
  56. }
  57. }
Success #stdin #stdout 0s 5288KB
stdin
1
1.00
stdout
Soda			price		inventory
Cola            0.75        20
Root Beer       0.75        20
Lemon-Lime      0.75        20
Grape Soda      0.80        20
Cream Soda      0.80        20
Pick a drink or quit program by pressing number
Cola (1), Root Beer (2), Lemon-Lime (3)
Grape Soda (4), Cream Soda (5), Quit (6)
Enter money inserted: 
Change 0.25
Soda			price		inventory
Cola            0.75        20
Root Beer       0.75        19
Lemon-Lime      0.75        20
Grape Soda      0.80        20
Cream Soda      0.80        20