Programming Language C++ Program for a vending machine.
#include <iostream>
using namespace std;
int main()
{
//variable declaration
int drink = 0;
string more = "y";
float bill = 0.0, cokePrice = 30.0, spritePrice = 42.0, waterPrice
= 20, snacksPrice = 60.0, tax = 0.0;
while( more == "y" || more == "Y")
{
cout << "Your choices of drinks are: " << endl;
cout << "1 - Coke" << endl;
cout << "2 - Sprite" << endl;
cout << "3 - Water" << endl;
cout << "4 - Snacks" << endl;
cout << "What drink would you like (1/4): ";
cin >> drink;
cout << endl;
switch(drink)
{
case 1 :
cout << "You chose Coke." << endl;
bill = bill + cokePrice;
break;
case 2 :
cout << "You chose Sprite." << endl;
bill = bill + spritePrice;
break;
case 3 :
cout << "You chose Water." << endl;
bill = bill + waterPrice;
break;
case 4 :
cout << "You chose Snacks." << endl;
bill = bill + snacksPrice;
break;
default :
cout << "Invalid Input";
}
cout <<endl<< "Would you like to order more? (Y/N):
";
cin >> more;
}
//calculate tax
tax = (bill * 18) / 100;
//calculate total bill
bill = bill + tax;
cout << endl;
cout <<"total Tax = "<<tax;
cout << endl;
cout <<"Total Bill = "<<bill;
return 0;
}
INPUT:
Your choices of drinks are:
1 - Coke
2 - Sprite
3 - Water
4 - Snacks
What drink would you like (1/4): 1
You chose Coke.
Would you like to order more? (Y/N): Y
Your choices of drinks are:
1 - Coke
2 - Sprite
3 - Water
4 - Snacks
What drink would you like (1/4): 4
You chose Snacks.
Would you like to order more? (Y/N): N
OUTPUT:
Total Tax = 16.2
Total Bill = 106.2
Get Answers For Free
Most questions answered within 1 hours.