Returning user to "main" function.

So here's the situation, I want to be able to have the user return to the gameStart() function once they completed the the GAMES within that function.
For example, the user selects the game they want (math, history, english) and when they finished the game, I want them to be able to return to the main menu.


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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include <iostream>
#include <string>
//#include "mathGAME.h"
//#include "englishGAME.h"
//#include "historyGAME.h"
//#include "gameStart.h"



using namespace std;

// mathGAME function


 void mathGAME(int& input, int& qone, int& qtwo, int& qthree)



{


	 cout << "Welcome to the Math Section of the Game\n ";
	 cout << "Please Select The LEVEL of Intensity Below \n";
	 cout << "[1]ADDITION    [2]SUBTRACTION   [3]MULTIPLICATION\n";
	 cin  >> input;
	 if (input == 1)
	 {
		 cout << "Lets begin with ADDITION \n";
		 cout << "\n ";
		 cout << "\n ";

		 // Question One

		 cout << "What's 2 + 2 : ";
		 cin  >> qone;
		 if (qone == 4){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Two

		 cout << "What's 10 + 15 : ";
		 cin  >> qtwo;
		 if (qtwo == 25){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Three

		 cout << "What's 100 + 1 : ";
		 cin  >> qthree;
		 if (qthree == 101){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";
	 }

	 else if (input == 2)
	 {
		 cout << "Lets begin with SUBTRACTION \n";
		 cout << "\n ";
		 cout << "\n ";

		 // Question One

		 cout << " What's 2 - 2 : ";
		 cin  >> qone;
		 if (qone == 0){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Two

		 cout << " What's 10 - 15 : ";
		 cin  >> qtwo;
		 if (qtwo == 5){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Three

		 cout << " What's 100 - 10 : ";
		 cin  >> qthree;
		 if (qthree == 90){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";
	 }

	 else if (input == 3)
	 {
		 cout << " Lets begin with MULTIPLICATION \n";
		 cout << "\n ";
		 cout << "\n ";

		 // Question One

		 cout << " What's 2 * 2 : ";
		 cin  >> qone;
		 if (qone == 4){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Two

		 cout << " What's 10 * 5 : ";
		 cin  >> qtwo;
		 if (qtwo == 50){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";

		 // Question Three

		 cout << " What's 5 * 5 : ";
		 cin  >> qthree;
		 if (qthree == 25){cout<<"Great Job !";}
		 else {cout<<"wrong \n ";}
		 cout << "\n ";
		 cout << "\n ";
	 }

	 else {cout << " Please select a VALID Entry \n";}



}// END OF mathGAME FUNCTION






// historyGAME function
void historyGAME(char& inputone, char& A, char& B, char& C)
{

  cout << "Welcome to the HISTORY Section of the Game\n ";
  cout << "For this game you must select the correct number \n";
  cout << "Enjoy and NO cheating !!! \n";
  cout << "\n";
  cout << "\n";


  // GAME STARTS HERE

  cout << "THE CURRENT PRESIDENT OF THE UNITED STATES IS : \n";
  cout << "[A] George Washington \n";
  cout << "[B] John Adams \n";
  cout << "[C] None of the Above \n";

  cin  >> inputone;
  if (inputone == C){ cout << " correct \n";}
  else {cout << " wrong \n";}
  //-----------------------------

  cout << "Who was the first President of the United States \n";
  cout << "[A] John Adams \n";
  cout << "[B] George Washington \n";
  cout << "[C] Andrew Jackson \n";
  cin  >> inputone;
  if (inputone == B){ cout <<" correct \n";}
  else {cout << " wrong \n";}
  //-----------------------------

  cout << "How many States are in the US ? \n ";
  cout << "[A] 500 States \n";
  cout << "[B] 400 States \n";
  cout << "[C] 50  States \n";
  cin  >> inputone;
  if (inputone == C) { cout <<" Great Job ! \n";}
  else {cout << " You Seriously Need to get your Head Checked \n";}


}

// englishGAME function
void englishGAME(char& inputtwo, char& d, char& e, char& f)
{


 cout << "This is the ENGLISH selection of the GAME... \n ";
 cout << "All you have to do for this game, is choose \n ";
 cout << "the word that is spelled correctly, THAT'S ALL \n";
 cout << "\n";
 cout << "\n";
 cout << "\n";

 // Question One

 cout << "Which word is spelled correctly \n";
 cout << "[d] Happy \n";
 cout << "[e] Funier \n";
 cout << "[f] Bestey \n ";
 cin  >> inputtwo;
 if (inputtwo == d) {cout << " great job ! \n";}
 else {cout << " wrong \n";}
 cout << "\n";
 cout << "\n";
 cout << "\n";

 // Question Two

 cout << "Which word is spelled correctly \n";
 cout << "[d] Mannerz \n";
 cout << "[e] Boycott \n";
 cout << "[f] Monkiey \n ";
 cin  >> inputtwo;
 if (inputtwo == e) {cout << " great job ! \n";}
 else {cout << " wrong \n";}
 cout << "\n";
 cout << "\n";
 cout << "\n";

 // Question Three

 cout << "Which word is spelled correctly \n";
 cout << "[d] Uglyis \n";
 cout << "[e] Good \n";
 cout << "[f] Badder \n ";
 cin  >> inputtwo;
 if (inputtwo == e) {cout << " great job ! \n";}
 else {cout << " wrong \n";}
 cout << "\n";
 cout << "\n";
 cout << "\n";

}

// Game's Main Menu
void gameStart(string selection, string math, string english, string history)
{

	int input, qone, qtwo, qthree;
	char inputone, A, B,C,inputtwo, d,e,f;

 cout << "Welcome to CommandLine Brainiac V1 \n"
		 "This is a simple game that tests your \n"
		 "Your MATH, ENGLISH & HISTORY skills. \n"
		 "\n"
		 "[math] [English] [history] \n";

 cin  >> selection;
 if (selection == "math"){mathGAME(input,qone,qtwo,qthree);}
 else if (selection == "English"){englishGAME(inputtwo,d,e,f);}
 else if (selection == "history"){historyGAME(inputone, A, B,C);}
 else {cout << " not a valid term \n";}

}









// The Main Application Lies Here

int main()

{


	string selection, math, english, history;
	gameStart(selection, math, english, history);


return 0;
}
Put a loop around lines 242-252.
What kind of loop ?
I still new to the looping concept.
What would be the line of code I have to
use to get that ?

I would do something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    while ( true )
    {
        cout << "Welcome to CommandLine Brainiac V1\n"
            "This is a simple game that tests your\n"
            "MATH, ENGLISH & HISTORY skills.\n\n"
            "[math] [English] [history] [quit]\n";

        cin  >> selection;

        if (selection == "math") mathGAME(input,qone,qtwo,qthree);
        else if (selection == "English") englishGAME(inputtwo,d,e,f);
        else if (selection == "history") historyGAME(inputone, A, B,C);
        else if (selection == "quit") return 0;
        else cout << " not a valid term \n";
    }
Last edited on
OMG Thanks man,
I didn't know it was that simple ...

Thanks,
samthewildone !
Oh, I just noticed that it's a void function so it should just be 'return' not 'return 0'.
wow im very thankful to this thread. i did not learn that i can create a header file
The things you learn by snooping around :D
yeah haha
Topic archived. No new replies allowed.