C++ CODE, Please organize the code so it is readable. Billy opened a slushy shop
ID: 3688294 • Letter: C
Question
C++ CODE, Please organize the code so it is readable.
Billy opened a slushy shop at the beach and has 3 slushy sizes he sells: small (9oz), medium (12oz). and large (15oz). the cost of one small cup is $1.75, one medium cup is $1.90, and one large cup is $2.00. Write a menu-driven program that will make the slushy shop operational. Your program should allow the user to do the following:
buy slushy 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 slushy sold (in ounces)
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 slushy, a function to show the number of cups of each size sold, a function to show the total amount of slushy sold, and a function to show the total money made. Your program should not use any global variables and special values such as slushy cup sizes and cost of a cup must be declared as global constants.
Explanation / Answer
#include <iostream>
using namespace std;
#define SMALL 1.75
#define MEDIUM 1.9
#define LARGE 2
void help() {
cout <<" You need to choose one of the menu options to select one of 3 slushys" <<endl;
cout << "Then enter the no of of slushys " <<endl;
}
int getOrder() {
int option;
do {
cout << "Choose one of the slushys" <<endl;
cout << "1. small (9oz) 2. medium (12oz) 3. large (15oz) 4.Exit" <<endl;
cin >> option;
} while(option <1 || option > 4);
return option;
}
void showCupsSold(int slushSold[]) {
cout <<"Slushy cups sold till now:" <<endl;
for(int i = 0; i < 3; i++) {
cout << (i == 0 ? "small (9oz)" : (i == 1 ? " medium (12oz)" : "large (15oz)" )) << slushSold[i] << endl;
}
}
void showTotalSold(int slushSold[]) {
cout << "Total slushys sold: " << (slushSold[0] * 9 +slushSold[1] * 12 +slushSold[2] * 15) << " oz" <<endl;
}
void showTotalAmount(int slushSold[]) {
float amount = (slushSold[0] * SMALL +slushSold[1] * MEDIUM +slushSold[2] * LARGE) ;
cout << "Total Amount: $" << amount << endl;
}
int main() {
help();
int option;
int noOfSlushyes= 0;
int slushSold[3] = {0,0,0};
do {
option = getOrder();
if(option == 4)
break;
do {
cout <<"Enter no of slushyes :" <<endl;
cin >>noOfSlushyes;
if(noOfSlushyes > 0) {
slushSold[option-1] += noOfSlushyes;
showCupsSold(slushSold);
showTotalSold(slushSold);
showTotalAmount(slushSold);
}
} while(noOfSlushyes < 0);
} while(option != 4);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.