1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever).
Then allow the user to choose a beverage by entering a number 1-5.
Output which beverage they chose.
★ If you program uses if statements instead of a switch statement, modify it to use a switch statement.
If instead your program uses a switch statement, modify it to use if/else-if statements.
★★ Modify the program so that if the user enters a choice other than 1-5 then it will output "Error. choice was not valid, here is your money back."
*/
#include <iostream>
#include <conio.h>
using namespace std;
int beverage; //gives user ability to choose which beverage they want
int coke=1; //type of beverage
double cokeprice= 1.25; //cost of coke beverage
int water=2; //type of beverage
double waterprice= 0.75; //cost of water
int sprite=3; //type of beverage
double spriteprice= 1.25; //cost of sprite
int fanta=4; //type of beverage
double fantaprice= 1.25; //cost of beverage
int powerade=5; //type of beverage
double poweradeprice= 1.5; //cost of beverage
double total; //used for telling user how much he/she owes the machine
int amount; //used for asking how much of the specific beverage they want
int main()
{
cout<<"Hello user choose any number of the five beverages listed below (1-5).\n\n"<<endl;
cout<<"1.Coke, price $1.25"<<endl;
cout<<"2.Water, price $0.75"<<endl;
cout<<"3.Sprite, price $1.25"<<endl;
cout<<"4.Fanta, price $1.25"<<endl;
cout<<"5.Powerade, price $1.50"<<endl;
cin>>beverage;
switch (beverage)
{
case 1:
{
cout<<"Thank you for choosing coke, how many would you like?"<<endl;
cin>>amount;
total=cokeprice*amount;
cout<<"The amount due is $"<<total<<"."<<endl;
break;
}
case 2:
{
cout<<"Thank you for choosing water, how many would you like?"<<endl;
cin>>amount;
total=waterprice*amount;
cout<<"The amount due is $"<<total<<"."<<endl;
break;
}
case 3:
{
cout<<"Thank you for choosing sprite, how many would you like?"<<endl;
cin>>amount;
total=spriteprice*amount;
cout<<"The amount due is $"<<total<<"."<<endl;
break;
}
case 4:
{
cout<<"Thank you for choosing fanta, how many would you like?"<<endl;
cin>>amount;
total=fantaprice*amount;
cout<<"The amount due is $"<<total<<"."<<endl;
break;
}
case 5:
{
cout<<"Thank you for choosing powerade, how many would you like?"<<endl;
cin>>amount;
total=poweradeprice*amount;
cout<<"The amount due is $"<<total<<"."<<endl;
break;
}
default:
{
cout<<"Error. choice was not valid, here is your money back."<<endl;
}
}
getch();
return 0;
}
|