hi i need a c++ program that does this but I need it in a very simple format usi
ID: 3824884 • Letter: H
Question
hi i need a c++ program that does this but I need it in a very simple format using only iostream int and not using std please
You opened a coffee shop at the beach and sells coffee in three sizes:
• small (9oz)
• medium (12oz)
• and large (15oz)
The cost of one small cup is $2.75, one medium cup is $2.90, and one large cup is $3.00.
Task
Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following:
• Buy coffee in any size and in any number of cups.
• At any time show the total number of cups of each size sold.
• At any time show the total amount of coffee sold.
• At any time show the total money made.
Your program should consist of at least the following functions:
• a function to show the user how to use the program,
• a function to sell coffee,
• a function to show the number of cups of each size sold,
• a function to show the total amount of coffee sold, and a function to show the total money made.
Your program should not use any global variables and special values such as coffee cup sizes and cost of a coffee cup must be declared as named constants
Explanation / Answer
Here is the code for you:
#include <iostream>
using namespace std;
int printMenu()
{
int choice;
cout<<"1. Buy Coffee."<<endl;
cout<<"2. Number of cups of each size."<<endl;
cout<<"3. Amount of coffee sold."<<endl;
cout<<"4. Total money made."<<endl;
cout<<"5. Exit."<<endl;
cout<<"Enter your choice: ";
cin>>choice;
return choice;
}
void sellCoffee(int& cupSize, int& numOfCups)
{
cout<<"1. Small (9oz) 2. Medium (12oz) 3. Large(15oz)."<<endl;
cout<<"Select your cup size: ";
cin>>cupSize;
cout<<"Enter the number of cups: ";
cin>>numOfCups;
}
void printNumOfCupsSold(int smallCups, int mediumCups, int largeCups)
{
cout<<"Small cups sold: "<<smallCups<<". Medium cups sold: "<<mediumCups<<". Large cups sold: "<<largeCups<<". ";
}
void printAmountOfCoffeeSold(int smallCups, int SMALL_OZ, int mediumCups, int MEDIUM_OZ, int largeCups, int LARGE_OZ)
{
cout<<"Total amount of coffee sold: "<< smallCups * SMALL_OZ + mediumCups * MEDIUM_OZ + largeCups * LARGE_OZ<<"oz."<<endl;
}
int main()
{
int smallCups = 0, mediumCups = 0, largeCups = 0, choice, numOfCups, cupSize;
double cupCost;
const double SMALL_PRICE = 2.75;
const int SMALL_OZ = 9;
const double MEDIUM_PRICE = 2.90;
const int MEDIUM_OZ = 12;
const double LARGE_PRICE = 3.00;
const int LARGE_OZ = 15;
while(true)
{
choice = printMenu();
switch(choice)
{
case 1: sellCoffee(cupSize, numOfCups);
if(cupSize == 1)
{
smallCups += numOfCups;
cupCost = SMALL_PRICE;
}
else if(cupSize == 2)
{
mediumCups += numOfCups;
cupCost = MEDIUM_PRICE;
}
else if(cupSize == 3)
{
largeCups += numOfCups;
cupCost = LARGE_PRICE;
}
cout<<"Here is your coffe... You should pay a total of: "<< cupCost * numOfCups<<endl;
break;
case 2: printNumOfCupsSold(smallCups, mediumCups, largeCups);
break;
case 3: printAmountOfCoffeeSold(smallCups, SMALL_OZ, mediumCups, MEDIUM_OZ, largeCups, LARGE_OZ);
break;
case 4: cout<<"Total money made: "<<smallCups * SMALL_PRICE + mediumCups * MEDIUM_PRICE + largeCups * LARGE_PRICE<<"$"<<endl; break;
case 5: return 0;
default: cout<<"Invalid menu option."<<endl;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.