help with coffee shop program!!

hi all,

I have to create a coffee shop program where you can:

• 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.


So far my code works fine. However, I can only view total cups sold/total money made etc for ONE transaction. I need to add a loop or something that allows the program to calculate the totals if there were multiple transactions.

Meaning if I ordered 2 small coffees, then selected yes to run the program again, and ordered 2 mediums, it should output 2 small and 2 medium sold, and give me a total money made of $11.30.

I know I probably have to include a loop, but I'm not sure where to put it and how I should go about it.

Can anyone give me any suggestions? thank you

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
118
119
120
121
122
123
  //Lab 8a
//A program that allows you to buy coffee, and at any time you can view total number of cups of each size sold, total amount of coffee sold, and total money made. 

#include <iostream>
#include <iomanip>

using namespace std;

const double smallcost = 1.75;
const double mediumcost = 1.90;
const double largecost = 2.00;
char choice;
void tutorial(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void sales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void sizesSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void totalCupsSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void totalSales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);


int main()
{
	int small;
	int medium;
	int large;
	int totalSmall;
	int totalMedium;
	int totalLarge;
	char runagain;
	do {
		tutorial(small, totalSmall, medium, totalMedium, large, totalLarge);

		cout << "Do you want to run this program again? Enter Y for yes and N for no: " << endl;
		cin >> runagain;

	} while (runagain == 'y' || runagain == 'Y');



}
void initialize(int & small, int & medium, int & large)
{
	small = 0;
	medium = 0;
	large = 0;

}
void tutorial(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	cout << "Please select which option you would like." << endl;
	cout << "1. Buy Coffee" << endl;
	cout << "2. Display the cups of coffee of each size sold" << endl;
	cout << "3. Display the total cups of coffee sold" << endl;
	cout << "4. Display the total amount of money earned" << endl;
	cin >> choice;

	switch (choice)
	{
	case '1':
		sales(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '2':
		sizesSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '3':
		totalCupsSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '4':
		totalSales(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	default:
		cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
	}

}
void sales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	initialize(small, medium, large);

	totalSmall = small;
	totalMedium = medium;
	totalLarge = large;

	cout << "Please read the menu, and select the number \nof each size of coffee that you would like to \npurchase.  If you would not like to purchase a certain \nsize of coffee, please enter '0'." << endl << endl;
	cout << "Small Cup........................ $" << showpoint << setprecision(3) << smallcost << endl;
	cout << "Medium Cup....................... $" << showpoint << setprecision(3) << mediumcost << endl;
	cout << "Large Cup........................ $" << showpoint << setprecision(3) << largecost << endl;
	cout << "Please enter the number of small cups you would like to purchase: ";
	cin >> small;
	cout << endl;
	cout << "Please enter the number of medium cups you would like to purchase: ";
	cin >> medium;
	cout << endl;
	cout << "Please enter the number of large cups you would like to purchase: ";
	cin >> large;
	cout << endl;
}
void sizesSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{

	totalSmall = small;
	totalMedium = medium;
	totalLarge = large;

	cout << "Number of small cups of coffee sold: " << totalSmall << endl;
	cout << "Number of medium cups of coffee sold: " << totalMedium << endl;
	cout << "Number of large cups of coffee sold: " << totalLarge << endl;
}
void totalCupsSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	totalSmall = small;
	totalMedium = medium;
	totalLarge = large;

	int totalCoffeeSold = totalSmall + totalMedium + totalLarge;
	cout << "The total number of coffee cups sold is: " << totalCoffeeSold << endl;
}
void totalSales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	totalSmall = small;
	totalMedium = medium;
	totalLarge = large;
	double moneyMade = (smallcost * totalSmall) + (mediumcost * totalMedium) + (largecost * totalLarge);
	cout << "Total Sales are: " << showpoint << moneyMade << endl;
It seems like the current sale would use the small/medium/large variables, and each time through the sale function, those individual totals would get accumulated into the totalSmall/totalMedium/totalLarge variables. Right now the total variables are getting set to whatever is in small/medium/large variables in several functions.
Here is a more refined version which does what you want.

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 //Lab 8a
//A program that allows you to buy coffee, and at any time you can view total number of cups of each size sold, total amount of coffee sold, and total money made. 

#include <iostream>
#include <iomanip>

using namespace std;

const double smallcost = 1.75;
const double mediumcost = 1.90;
const double largecost = 2.00;
char choice;
void tutorial(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void sales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void sizesSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void currentSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void totalCupsSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void totalSales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);

int main()
{
	int small = 0;
	int medium = 0;
	int large = 0;
	int totalSmall = 0;
	int totalMedium = 0;
	int totalLarge = 0;
	char runagain;

	do {
		tutorial(small, totalSmall, medium, totalMedium, large, totalLarge);

		cout << "Do you want to run this program again? Enter Y for yes : ";
		cin >> runagain;

	} while (runagain == 'y' || runagain == 'Y');
}

void initialize(int & small, int & medium, int & large)
{
	small = 0;
	medium = 0;
	large = 0;
}

void tutorial(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	cout << fixed << setprecision(2) << endl;

	cout << "Please select which option you would like." << endl;
	cout << "1. Buy Coffee" << endl;
	cout << "2. Display the cups of coffee of each size sold" << endl;
	cout << "3. Display the total cups of coffee sold" << endl;
	cout << "4. Display the total amount of money earned" << endl;
	cout << "Your choice : ";
	cin >> choice;
	cout << endl;

	switch (choice)
	{
	case '1':
		sales(small, totalSmall, medium, totalMedium, large, totalLarge);
		currentSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '2':
		sizesSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '3':
		totalCupsSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '4':
		totalSales(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	default:
		cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
	}

}
void sales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	cout << "Please read the menu, and select the number \nof each size of coffee that you would like to \npurchase.  If you would not like to purchase a certain \nsize of coffee, please enter '0'." << endl << endl;
	cout << "Small Cup........................ $" << showpoint << setprecision(3) << smallcost << endl;
	cout << "Medium Cup....................... $" << showpoint << setprecision(3) << mediumcost << endl;
	cout << "Large Cup........................ $" << showpoint << setprecision(3) << largecost << endl;
	cout << endl;
	cout << "Please enter the number of cups you would like to purchase : ";
	cout << endl;
	cout << "+ Small cups you would like to purchase : ";
	cin >> small;
	cout << "+ Medium cups you would like to purchase : ";
	cin >> medium;
	cout << "+ Large cups you would like to purchase : ";
	cin >> large;
	cout << endl;

	totalSmall += small;
	totalMedium += medium;
	totalLarge += large;
}

void sizesSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	cout << "Total number of small coffee cups sold : " << totalSmall << " ($" << (totalSmall * smallcost) << ")" << endl;
	cout << "Total number of medium coffee cups sold : " << totalMedium << " ($" << (totalMedium * mediumcost) << ")" << endl;
	cout << "Total number of large coffee cups sold : " << totalLarge << " ($" << (totalLarge * largecost) << ")" << endl;
	cout << endl;
}

void currentSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	double moneyMade = 0;
	moneyMade += small * smallcost;
	moneyMade += medium * mediumcost;
	moneyMade += large * largecost;

	int totalCoffeeSold = small + medium + large;
	cout << "The number of coffee cups sold is : " << totalCoffeeSold << endl;
	cout << "Money earned is : $" << showpoint << moneyMade << endl;
	cout << endl;

	small = 0;
	medium = 0;
	large = 0;
}

void totalCupsSold(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	int totalSold = totalSmall + totalMedium + totalLarge;
	cout << "The total number of coffee cups sold is : " << totalSold << endl;
	cout << endl;
}

void totalSales(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)
{
	double moneySales = 0;
	moneySales += totalSmall * smallcost;
	moneySales += totalMedium * mediumcost;
	moneySales += totalLarge * largecost;

	cout << "Total Sales are : $" << showpoint << moneySales << endl;
	cout << endl;
}
@Mantorr22

You should comment the changes you made, the code looks very similar to the OP's. I am not saying you didn't change anything, just that I couldn't be bothered to look in detail to see what you did change. I wouldn't say that it is more refined either.

@tayyeb

It seems like a lot of code to keep track of the sales for 3 different sizes of coffee. You have lots of functions which you send arguments that aren't used, as in you are sending all the variables to all the functions. Why not have 3 functions, 1 for the sale of each size? Send the total variable and number for that size by reference. Then do the grand totals.

@Mantorr22

Thank you so much!! Your revisions worked like a charm :) I see you created a new function, currentSold which allows the program to keep track of current cups being sold, thus separating total cups from the cups being sold at the present moment. I was trying to create a new variable that would store the value of cups sold, but I realize that this makes a lot more sense.

thanks again!


@TheIdeasMan

Unfortunately, my professor was sort of a stickler about us creating functions for each task. Essentially, she really wanted us to understand functions, so even though the code wasn't exactly efficient, it was what she wanted in the sense that there was a separate function for each task.

Unfortunately, my professor was sort of a stickler about us creating functions for each task.


That is fine, but IMO you are over doing it. The main problem is sending all variables to all functions. The functions could be much simpler. You can still have a function for each task, just organise them differently.

Any way, just trying to help you possibly get more marks for your assignment.
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
#include <iostream>
#include <iomanip>
#include<cstring>
using namespace std;

const double smallcost = 1.75;
const double mediumcost = 1.90;
const double largecost = 2.00;
char choice;
void tutorial(int & small, int & medium, int & large );
void sales(int & small, int & medium, int & large);
void sizesSold(int & small, int & medium, int & large);
void totalCupsSold(int & small, int & medium, int & large);
void totalSales(int & small, int & medium, int & large);


int main()
{
    int small = 0;
    int medium = 0;
    int large = 0;

    char runagain;

    do {
        tutorial(small,medium, large);

        cout << "Do you want to run this program again? Enter Y for yes and N for no: " << endl;
        cin >> runagain;
        system("cls");

    } while (runagain == 'y' || runagain == 'Y');



}

void tutorial(int & small, int & medium, int & large)
{
    cout << "Please select which option you would like." << endl;
    cout << "1. Buy Coffee" << endl;
    cout << "2. Display the cups of coffee of each size sold" << endl;
    cout << "3. Display the total cups of coffee sold" << endl;
    cout << "4. Display the total amount of money earned" << endl;
    cin >> choice;

    switch (choice)
    {
    case '1':
        sales(small, medium, large);
        break;
    case '2':
        sizesSold(small, medium, large);
        break;
    case '3':
        totalCupsSold(small, medium, large);
        break;
    case '4':
        totalSales(small, medium, large);
        break;
    default:
        cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
    }

}
void sales(int & small , int & medium , int & large)
{
    string size;

    cout << setw(50) << "MENU" << endl << endl;
    cout << setw(60) << "small ........................ $" << showpoint << setprecision(3) << smallcost << endl;
    cout << setw(60) <<"medium ....................... $" << showpoint << setprecision(3) << mediumcost << endl;
    cout << setw(60) <<"large ........................ $" << showpoint << setprecision(3) << largecost << endl;
    cout << setw(60) <<"Please read the menu, and select the size of the coffee that you \nwould like to purchase." << endl << endl;

    cin>>setw(6)>>size;

    if(size == "small")
    {
        cout<<"How many small coffee's would you like sir?"<<endl;
        cout<<":";
        cin>>small;
    }
    else if(size == "medium")
    {
        cout<<"How many medium coffee's would you like sir?"<<endl;
        cout<<":";
        cin>>medium;
    }
    else if(size == "large")
    {
        cout<<"How many large coffee's would you like sir?"<<endl;
        cout<<":";
        cin>>large;
    }
}
void sizesSold(int & small, int & medium, int & large)
{
    cout << "\nNumber of small cups of coffee sold: " << small << endl;
    cout << "Number of medium cups of coffee sold: " << medium << endl;
    cout << "Number of large cups of coffee sold: " << large << endl;
}
void totalCupsSold(int & small, int & medium, int & large)
{
    int totalCoffeeSold = 0;
    totalCoffeeSold = small + medium + large;
    cout << "\nThe total number of coffee cups sold: " << totalCoffeeSold << endl;
}
void totalSales(int & small, int & medium, int & large)
{
    double moneyMade = (smallcost * small) + (mediumcost * medium) + (largecost * large);
    cout << "Total Sales are: $" << showpoint << setprecision(2) << fixed <<moneyMade << endl;
}

:) hope this is what you are looking for. I think that the totalSmall, totalMedium and totalLarge are irrelevant in the parameters and throughout the program *my personal opinion*
Last edited on
I think that the totalSmall, totalMedium and totalLarge are irrelevant in the parameters and throughout the program


But if they need to let the guy ordering coffee how much his total is, the program might need to keep track of the current sale separately from the overall totals. What if he wants to order a small and a medium at the same time? Right now only one size can be ordered in one sale, and the full size name has to be typed in instead of just a one character option from a menu.
Topic archived. No new replies allowed.