menu-driven program help

hello, this problem has been stressing me out
problem: Jason opened a coffee shop at the beach and sells coffee in three sizes; small(9oz) meduium (12oz) and large (15oz).the cost of one small is $1.75, one medium is 1.90$, and one large is 5.00$. Write a menu-Driven program that will make the coffee shop operational. Your program should allow the user to do the following:
A)Buy Coffee in any size and in any number of cups.
B)At any time show the total number of cps of each size sold.
C)At anytime show the total number of coffee sold.
D)At any time show the total money made.

Your program should consist of tat 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 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.

Heres what I have (how do implement the total money made) also did I do the rest correctly?

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
 #include<iostream>
#include <cmath>
#include <iomanip>
 
using namespace std;

 int main()
 {

   char Size;
   double Total = 0.0;
   int Cupcount = 0;
   const double Small = 1.75; 
   const double Medium = 1.90; 
   const double Large = 2.00;

   cout << "Coffee\n\n";
   cout << "Small Cup = " << Small;
   cout << "Medium Cup = " << Medium;
   cout << "Large Cup = " << Large;


   cout << "\n\nWould you like a Large (L), Medium (M), or Small (S) coffee? ";
   cin >> Size;
   if(Size >90) Size -= 32;

   while((Size == 'L')||(Size == 'M')||(Size == 'S'))
   {
     ++Cupcount;

 if(Size == 'L')
 Total + Large;
 if(Size == 'M')
 Total + Medium;
 if(Size == 'S')
 Total + Small;


     cout << "\nSo far " << Cupcount << " cups of coffee have been sold :";
     cout << " Your Total is: $ " << Total << endl;

 

 system("pause");
 return 0; 
 }
Last edited on
Hey I fixed up your program for you and added all of the features that were required. I made it way more complicated than it had to be so sorry about that haha. Also there is NO error-handling in this. You'll have to implement that on your own.
1
2
3
4
5
6
7
8
9
10
11
12
Main.cpp

#include "CoffeeShop.h"

int main()
{
	CoffeeShop Shop;

	Shop.Menu();

	return 0;
}


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
CoffeeShop.h

#pragma once

#include <iostream>
#include <iomanip>
#include <utility>
#include <sstream>
#include <string>

class CoffeeShop
{
public:
	void Menu();
	void BuyCoffee(int type, int amount);
	void ShowCoffeeSold();
	void ShowProfit();
	std::pair<int, int> ParseString(const std::string &TypeAmount);

private:
	double profit = 0;

	const double smallPrice = 1.75;
	const double mediumPrice = 1.90;
	const double largePrice = 5.00;

	int smallsSold = 0;
	int mediumsSold = 0;
	int largesSold = 0;
};


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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
CoffeeShop.cpp

#include "CoffeeShop.h"

void CoffeeShop::Menu()
{
	std::string coffeeInput;

	while(coffeeInput != "exit")
	{
		std::cout << "Jason's Coffee Shop\n\n";
		std::cout << "Menu\n";
		std::cout << "#\tItem\t\tPrice\n";
		std::cout << "1\tSmall Coffee\t$1.75\n";
		std::cout << "2\tMedium Coffee\t$1.90\n";
		std::cout << "3\tLarge Coffee\t$5.00\n\n";

		std::cout << "Enter coffee # that you wish to purchase followed by a ',' and the amount or\n enter '4' to view total cups of each size sold\t'5' to view profit: ";

		std::getline(std::cin, coffeeInput);

		std::pair<int, int> parsedString = ParseString(coffeeInput);

		system("cls");

		switch(parsedString.first)
		{
			case 1:
			case 2:
			case 3:
				system("cls");
				BuyCoffee(parsedString.first, parsedString.second);
				break;
			case 4:
				system("cls");
				ShowCoffeeSold();
				break;
			case 5:
				system("cls");
				ShowProfit();
				break;
		}
	}
}

void CoffeeShop::BuyCoffee(int type, int amount)
{
	switch(type)
	{
		case 1:
			profit += smallPrice * amount;
			smallsSold += amount;
			std::cout << amount << " small coffie(s) bought for $" << smallPrice * amount;
			break;
		case 2:
			profit += mediumPrice * amount;
			mediumsSold += amount;
			std::cout << amount << " medium coffie(s) bought for $" << mediumPrice * amount;
			break;
		case 3:
			profit += largePrice * amount;
			largesSold += amount;
			std::cout << amount << " large coffie(s) bought for $" << largePrice * amount;
			break;
	}

	std::cout << "\n\nPress enter to continue.";
	std::cin.ignore();
	system("cls");
}

void CoffeeShop::ShowCoffeeSold()
{
	std::cout << "Coffee Sold\n\n";
	std::cout << "Type\t\tAmount\n";
	std::cout << "Small\t\t" << smallsSold << "\n";
	std::cout << "Medium\t\t" << mediumsSold << "\n";
	std::cout << "Large\t\t" << largesSold << "\n\n";
	std::cout << "Total\t\t" << smallsSold + mediumsSold + largesSold << "\n\n";

	std::cout << "\n\nPress enter to continue.";
	std::cin.ignore();
	system("cls");
}

void CoffeeShop::ShowProfit()
{
	std::cout << "Profit\n\n";
	std::cout << "Profit some small coffies: " << smallsSold * smallPrice << "\n";
	std::cout << "Profit some medium coffies: " << mediumsSold * mediumPrice << "\n";
	std::cout << "Profit some large coffies: " << largesSold * largePrice << "\n";
	std::cout << "Total profit: " << (smallsSold * smallPrice) + (mediumsSold * mediumPrice) + (largesSold * largePrice);

	std::cout << "\n\nPress enter to continue.";
	std::cin.ignore();
	system("cls");

}

std::pair<int, int> CoffeeShop::ParseString(const std::string &TypeAmount)
{
	std::istringstream iss(TypeAmount);

	std::string tempType;
	std::getline(iss, tempType, ',');

	std::string tempAmount;
	std::getline(iss, tempAmount);

	int type;
	std::istringstream(tempType) >> type;

	int amount;
	std::istringstream(tempAmount) >> amount;

	return std::pair<int, int>(std::move(type), std::move(amount));
}


I hope it helps!

EDIT:
If you're not running on windows, remove all of the system("cls") and just add some new lines if you want.
Last edited on
Topic archived. No new replies allowed.