Homework Help

Hi, this is my very first post on this website, and unfortunately I need some help with writing a program for a c++ class. Hopefully I'll be able to return the favor at some point. Here's the problem:
Jason 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 of coffee 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 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 cups of each size sold.
c. At any time show the total amount of coffee sold.
d. 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.

I'm having so much trouble with functions. I could do this program without any trouble without any trouble if I didn't have to use them! I'm currently getting an error message that says "tutorial function does not take 6 arguments." and I really don't know why. I also just in general don't understand functions and reference variables very well, so if this program is a total train wreck design wise, that's why. Any help would be appreciated.
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
 #include <iostream>
#include <iomanip>

using namespace std;

const double SMALL_CUP_COST = 1.75;
const double MEDIUM_CUP_COST = 1.90;
const double LARGE_CUP_COST = 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 & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge);
void totalCupsSold(int & totalSmall, int & totalMedium, int & totalLarge);
void totalSales(int & totalSmall, int & totalMedium, int & totalLarge);











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

	system("pause");
	return 0;
	
}
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, medium, large);
		break;
	case '2':
		sizesSold(small, totalSmall, medium, totalMedium, large, totalLarge);
		break;
	case '3':
		totalCupsSold(totalSmall, totalMedium, totalLarge);
		break;
	case '4':
		totalSales(totalSmall, totalMedium, totalLarge);
		break;
	default:
		cout << "Invalid number selection. Please select a number between 1 and 4." << endl;
	}

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

	cout << "Please read the menu, and select the number " << endl;
	cout << "of each size of coffee that you would like to " << endl;
	cout << "purchase.  If you would not like to purchase a certain " << endl;
	cout << "size of coffee, please enter '0'." << endl << endl;
	cout << "Small Cup........................ $" << showpoint << setprecision(3) << SMALL_CUP_COST << endl;
	cout << "Medium Cup....................... $" << showpoint << setprecision(3) << MEDIUM_CUP_COST << endl;
	cout << "Large Cup........................ $" << showpoint << setprecision(3) << LARGE_CUP_COST << 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 = totalSmall + small;
	totalMedium = totalMedium + medium;
	totalLarge = 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 & totalSmall, int & totalMedium, int & totalLarge)
{
	int totalCoffeeSold = totalSmall + totalMedium + totalLarge;
	cout << "The total number of coffee cups sold is: " << totalCoffeeSold << endl;
}
void totalSales(int & totalSmall, int & totalMedium, int & totalLarge)
{
	double moneyMade = (SMALL_CUP_COST * totalSmall) + (MEDIUM_CUP_COST * totalMedium) + (LARGE_CUP_COST * totalLarge);
	cout << "Total Sales are: " << showpoint << moneyMade << endl;
}
Above main, when you're prototyping your tutorial function

void tutorial(int & small, int & medium, int & large); It doesnt take 6 arguments, thats why you're getting that error. Change it so it looks like the actual function definition.

Edit: Runs fine once this is changed.
Last edited on
You declare tutorial on line 10 as:
void tutorial(int & small, int & medium, int & large);

But then on line 46 you define it as:
void tutorial(int & small, int & totalSmall, int & medium, int & totalMedium, int & large, int & totalLarge)

The compiler is expecting a function with 3 arguments, but you deliver one with 6. Change the first declaration to accommodate the extra arguments perhaps?
Last edited on
thank you, I didn't realize that. sorry about the double post. It gave me an error the first time I tried so I figured that the post didn't go through.
It did go through, I linked that post to this one so if some ppl in the future happen to come across it.
So now the program runs, but doesn't work. It gives strange values if options 2-4 are selected. I'm wondering if this is due to the program terminating after I enter in the order, or if it is caused by not initializing any of the 'total' variables.
Its because when you created the variables, you never initialized them, so they just got garbage values, thats what you're seeing, so initialize them like this

1
2
3
4
5
6
int small = 0;
int medium = 0;
int large = 0;
int totalSmall = 0;
int totalMedium = 0;
int totalLarge = 0;
So you are saying to do this in the main function, correct? and eliminate the initialize function? Won't this make the value zero everytime the program starts?
Yes. If no one buys anything, it will stay 0, that is logical right? But obviously once ppl buy shit, it doesnt matter what their value was in the beginning because those values will be changed.
I just did this a couple weeks ago. Here is the main function. It might help.

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
/*******************************************************************************
**  Author	:  Donald "Chris" Moore
**  Date		:  2 April 2015
**  File		:  Assignment-6.cpp
**  Assignment	:  Jason opened a coffee shop at the beach and sells coffee 
**		in three sizes:  small (9 oz), medium (12 oz), and large (15 oz). 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 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 cups of each size sold.
**			C.  At any time show the total amount of coffee sold.
**			D. At any time show the total money made(gross income).
**		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
**			a function to show the total amount of money made.
**		Your program should not use any global variables. Special values
**		such as coffee cup sizes and cost of a coffee cup must be declared as 
**		named constants.
**  Input from  :  Console
**  Output to	:  Console
*******************************************************************************/
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

// Named Constants
const double SM_CST = 1.75;     //  cost of a small cup
const double MD_CST = 1.90;     //  cost of a medium cup
const double LG_CST = 2.00;     //  cost of a large cup
const int SM_OZ = 9;     //  number of ounces in a small cup
const int MD_OZ = 12;     //  number of ounces in a medium cup
const int LG_OZ = 15;     //  number of ounces in a large cup

//Function prototypes
void showMenu();  //  makes the menu for the main function.
int getChoice(int& ch);  //  obtains the choice for the main menu.
void buyCoffee(int& SmCups, int& MdCups, int& LgCups);
void cupSold(int SmCups, int MdCups, int LgCups);
void coffeeSold(int SmCups, int MdCups, int LgCups);
void totalAmount(int SmCups, int MdCups, int LgCups);
void userGuide();     //  shows the user guide 
void buyMenu();     //  makes the menu for the buyCoffee function.
int howMany(int num);     //  finds out howMany cups for the buyCoffee function.
void toContinue();     //  asks user if they are ready to continue
void cPrinCenter(string words);     //  function to center print in 80 console

//******************************************************************************
//    the beginning of 'main' function
//******************************************************************************
int main()
{
	// declare / initialize variables
	int numSmCups = 0;
	int numMdCups = 0;
	int numLgCups = 0;
	int choice = 0;

	cout << fixed << showpoint << setprecision(2);
	do	//	begin the main loop structure
	{
		showMenu();
		//	getChoice switch calls function to show the main menu
		switch (getChoice(choice))
		{
		case 1:
			buyCoffee(numSmCups, numMdCups, numLgCups);
			break;
		case 2:
			cupSold(numSmCups, numMdCups, numLgCups);
			break;
		case 3:
			coffeeSold(numSmCups, numMdCups, numLgCups);
			break;
		case 4:
			totalAmount(numSmCups, numMdCups, numLgCups);
			break;
		case 5:
			userGuide();
			break;
		case 9:
			//  this is the end, nothing to see here...
			break;
		default:
			cout << "Invalid input." << endl;
			toContinue();
		}
	} while (choice != 9);

	cout << " Thank you for using this program.  Have a nice day." << endl;
	return 0;
}   //	end main 
Ok, so I see what you are saying, but I ran through the program, and selected to buy at least one cup of each type of coffee, closed the program, ran it again, this time selecting to view the number of cups of each size sold. All of the values were zero. I need this program to keep a running total of how many of each type is sold, and save those values even after the program closes. Sorry if I didn't make that clear. Would this be fixed by using a do while loop as shown above?
Topic archived. No new replies allowed.