Write a program that emulates a soft drink vending machine.
Use an if-else-if block to handle a menu of the following options:
1) Coke, 2)Sprite, 3) Sprite, 4) Ice tea.
Output Example
Vending Machine
1) Coke
2) Sprite
3) Water
4) Ice tea
Select: 4
You selected an Ice tea.
#include <iostream>
using namespace std;
string drink[4] {
"Coke",
"Sprite",
"Water",
"Ice tea"
};
int main()
{
cout << "Vecding Machine\n";
for (int i = 0; i < 4; i++) {
cout << i + 1 << ") " << drink[i] << "\n";
}
int n;
cout << "Select: ";
cin >> n;
cout << "You selected a" << (n == 4 ? "n " : " ");
if (n == 1)
cout << drink[0];
else if (n == 2)
cout << drink[1];
else if (n == 3)
cout << drink[2];
else if (n == 4)
cout << drink[3];
else
cout << "=(";
return 0;
}
Comments
Leave a comment