C++ Functions Assistance

closed account (Ezq4G16C)
Hello All! I am new to C++ and am currently stuck doing this problem. I am having toruble on figuring out how to go about doing the sell games function which can set up all the other functions but I do not know how to go about adding the games together with the price and then getting the running sales total.

Before you can open the shop you need to develop a program that will track some sales
information. Your program should allow the user to do the following:
1. Buy any number of games of the three types
2. At any time show the total number of games sold of each type
3. At any time show the total number of games sold
4. At any time show the total amount of money made
The program should consist of at least the following functions:
 A function which displays an intro screen to your shop including your shops name
o Void function with no parameters
 A function to act as the program’s main menu
o Value returning function which displays the user choices and returns the selection
 A function to act as the game purchase menu
o Value returning function which displays the game choices and returns the
selection
 A function to sell games
o Void function with reference parameters
o Calls the game menu function, process and tracks the sale information
 A function to show the total number of games sold
o Void function with one parameter which displays the total number of games sold
 A function to show the total number of games sold of each type
o Void function with three parameters which displays the total number of games
sold of each type
 A function to show the total amount of money made
o Void function with one parameter which displays the total amount of money made
Your program can not use any global variables and special values such as game prices must be
declared as named constants.


This is what I have so far:

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include "main.h"
#include <string>

using namespace std;

int main()
{
	// Variable Declarations
	const double singleCost = 10.99; // constant price variable for single A game
	const double doubleCost = 20.99; // constant price variable for double A game
	const double tripleCost = 40.99; // constant price variable for triple A game
	int singleA = 0 , totalSingle = 0;
	int doubleA = 0 , totalDouble = 0;
	int tripleA = 0 , totalTriple = 0;
	const int EXIT = 9;
	int userEntry = 0;

// Intro screen
	IntroScreen();

// Main Menu
	while (userEntry != EXIT)
	{
		
		userEntry = MainMenu(); // displays main menu and waits for user entry

		if (userEntry == 1)
		{
			GameMenu(); // displays game sale menu
		}
		else if (userEntry == 2)
		{
			totalSales(singleA, totalSingle, doubleA,totalDouble, tripleA, totalTriple);
			// calls function for total money made
		}
		else if (userEntry == 3)
		{
			// calls function for total amount of games sold
		}
		else if (userEntry == 4)
		{
			// calls function for number of game types sold
		}
		else if (userEntry == 5)
		{
			// calls function for all sales information
		}
	}
	system("pause");
	return 0;
}

// FUCNTIONS 
// Intro Screen Function
void IntroScreen()
{
	cout << "************************************************************" << endl;
	cout << "**                                **" << endl;
	cout << "**                         **" << endl;
	cout << "**             **" << endl;
	cout << "************************************************************" << endl;

	system("pause");
}
// Main Menu Function
int MainMenu()
{
	int userSelection; // variables
	bool exit = false;

	while (exit == false) // loop until the user enters a valid entry
	{
		system("cls");

		cout << "1. Enter 1 to sell a game\n";                     // display the menu to the user
		cout << "2. Enter 2 to check the total money made up to this time\n";
		cout << "3. Enter 3 to check the total amount of games sold up to this time\n";
		cout << "4. Enter 4 check the number of game types sold\n";
		cout << "5. Enter 5 to check all sales information\n";
		cout << "9. Enter 9 to quit the program\n";
		cout << "Enter your choice: ";
		cin >> userSelection;	// get the user entry	

		switch (userSelection)		// check if its valid, if so return the value otherwise loop	
		{
		case 1: 
		case 2:
		case 3:
		case 4:
		case 5:
		case 9:
			exit = true;
			break;
		default:
			cout << "You've entered a invalid selection. Please enter 1 - 5 or 9 \n";
			system("pause");
		}
	}
	return userSelection;
}
// Sell Games Menu function
int GameMenu()
{
	int userSelection;
	bool exit = false;
	int singleA = 0 , totalSingle = 0;
	int doubleA = 0 , totalDouble = 0;
	int tripleA = 0 , totalTriple = 0;

	while (exit == false)
	{
		system("cls");

		cout <<     "***************** Game Menu *****************" << endl;
			cout << "1. Please enter 1 to buy a Single A game" << endl;
			cout << "2. Please enter 2 to buy a Double A game" << endl;
			cout << "3. Please enter 3 to buy a Triple A game" << endl;
			cout << "9. Please enter 9 to go back to the main menu" << endl;
			cin >> userSelection;

			switch (userSelection)
			{
			case 1: 
				cout << "Enter how many Single A games purchased: ";
				cin >> singleA;
			case 2:
			case 3:
			case 9:
				exit = true;
				break;
			default:
				cout << "You have entered an invalid selection. Please enter a 1-3 or 9.\n";
				system("pause");
			}
	}
	return 0;
}

// Sell Games Function
void SellGames (int& singleA, int& doubleA, int& tripleA, int& gamesSold, int& totalMoney)
{
	
	
}

// Total Games Sold Function
void TotalGames(int totalSold)
{
	int totalSold = totalSingle + totalDouble + totalTriple;
	cout << "The total number of games sold is: " << totalSold << endl << endl;
}

// Total Number of Games Sold of Each type
void GameCount(int& totalSingle, int& totalDouble, int& totalTriple)
{
	cout << "Total number of Single A games sold: " << totalSingle;
	cout << "Total number of Double A games sold: " << totalDouble;
	cout << "Total number of Triple A games sold: " << totalTriple;

}

// Total amount of money made function
void totalSales (int& singleA, int& totalSingle, int& doubleA, int& totalDouble, int& tripleA, int& totalTriple)
{
	const double singleCost = 10.99; 
	const double doubleCost = 20.99; 
	const double tripleCost = 40.99; 
	double totalMoney = 0;
		
	totalMoney += totalSingle * singleCost;
	totalMoney += totalDouble * doubleCost;
	totalMoney += totalTriple * tripleCost;

}

Last edited on
The function isn't the problem, I think the problem is that you haven't thought about how you're going to represent your inventory. You have pricing, but you don't have anything for sale.

You could start with a list of games, and assume they're all the same prices, so you can apply your pricing stuff.

To simplify things, you could assume that you have enough stock, so you don't need to think about running out of a particular game. In which case, you'd just have list of games.

You could add an option buy each game, and have a checkout option, where the games are actually processed. At this point, you'll have a list of games where you can apply your discounts. The checkout might look like this:
1
2
3
4
double checkout(int numberOfGames) {
    // apply prices for the number of games purchased
    // return total;
}
Topic archived. No new replies allowed.