fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct soda
  6. {
  7. string name;
  8. float cost;
  9. int inventory;
  10. };
  11.  
  12. soda GetSodaInfo();
  13.  
  14. void DisplaySodaOptions(soda drinks[], int SIZE);
  15.  
  16. int main()
  17. {
  18. //Create Array to Hold Soda Info
  19. const int SIZE = 5;
  20. soda drinks[SIZE];
  21.  
  22. //Store Info for Each Soda
  23. for (int i = 0; i < SIZE; ++i)
  24. {
  25. drinks[i] = GetSodaInfo();
  26. }
  27. cout << endl;
  28.  
  29. //Display Soda Options
  30. DisplaySodaOptions(drinks, SIZE);
  31. cout << endl;
  32.  
  33. //User Select Option
  34. cout << "Enter Choice (1-5): ";
  35.  
  36.  
  37. return 0;
  38. }
  39.  
  40. soda GetSodaInfo()
  41. {
  42. soda x;
  43. cout << "Enter Soda Information: Press Enter After Each Entry: " << endl;
  44. cin >> x.name;
  45. cin >> x.cost;
  46. cin >> x.inventory;
  47. return x;
  48. }
  49.  
  50. void DisplaySodaOptions(soda drinks [], int SIZE)
  51. {
  52. cout << "Enter Soda Selection: " << endl << endl;
  53. cout << "Options are: " << endl;
  54.  
  55. for (int i = 0; i < SIZE; ++i)
  56. {
  57. cout << i + 1 << ". " << drinks[i].name;
  58. if(i < SIZE - 1)
  59. cout << ", ";
  60. }
  61. cout << endl;
  62. }
  63.  
  64.  
  65.  
Success #stdin #stdout 0s 5320KB
stdin
Coke
2.75
15
A&W
2.50
3
Sprite
.50
0
Crush
2.50
40
Cream
1.00
28
stdout
Enter Soda Information: Press Enter After Each Entry: 
Enter Soda Information: Press Enter After Each Entry: 
Enter Soda Information: Press Enter After Each Entry: 
Enter Soda Information: Press Enter After Each Entry: 
Enter Soda Information: Press Enter After Each Entry: 

Enter Soda Selection: 

Options are: 
1. Coke, 2. A&W, 3. Sprite, 4. Crush, 5. Cream

Enter Choice (1-5):