Conversion table with menu and sub menu

I'm having trouble making this work. I'm taking a class and I don't get how to do this. I've done the reading but, it's an online class and the teacher isn't very helpful. I'm new at programming and for some reason I decided to start with C++

/*
Write a program that will do simple conversations of lengths, weights, volumes, and areas. You
program will of course contain a main() that will call a function to start the program. The
function called by the main() will contain a menu that offers the user a number of main options
such as Lengths, Weights, Volumes, and Areas. Once the user selects an option the program
will proceed to another function which will give the user the sub options such as Inches to
centimeters, yards to meters and miles to kilometers. The main menu must loop until the user
indicates the user wishes to quit the program.

You must also write a print() function which takes in arguments needed to display the results
each time a conversion has taken place. Once a conversion is completed and displayed, the
user should be sent back to the main menu and asked if they wish to continue or would like to
select another option.
*/


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

double number, answer;
char optionA, optionL, optionW, optionV, optionAr, quit;

void printIntroduction();
void mainMenu();
void printQuit();
void printGoodBye();
void lengthMenu();
void areaMenu();
void volumeMenu();
void weightMenu();
void printAnswer();
// Lengths
void inchesToCentimeters();
void yardsToMeters();
void milesToKilometers();
// Weights
void ouncesToGrams();
void poundsToKilograms();
void tonsToKilograms();
// Volumes
void pintsToLiters();
void quartsToLiters();
void gallonsToLiters();
// Areas
void sqInchesToSqMillimeters();
void sqFeetToSqMeters();
void acresToSqMeters();


double enterData();
void printAnswer(double, string, double, string);

int main()
{
printIntroduction();
mainMenu();
printQuit;
printGoodBye();

system("pause");
return(0);

}

void printIntroduction()
{
cout << "\tWelcome to the measurment conversion tool." << endl;
}
void printQuit()
{
cout << "Would you like to continue? y/n: ";
cin >> quit;
if (quit = 'Y' || 'y')
{
void printgoodbye();
}
else
{
void mainmenu();
}

}

void printGoodBye()
{
cout << "\n\nGood bye, ya\'ll come back soon!\n\n" << endl;
}
void mainMenu()
{
cout << "L = Lengths" << endl;
cout << "W = Weights" << endl;
cout << "V = Volumes" << endl;
cout << "A = Areas" << endl;
cout << "Q = Quit" << endl;
cout << "Choose an option: ";
cin >> optionA;
if (optionA = 'L' || 'l')
{
lengthMenu();
}
if (optionA = 'W' || 'w')
{
weightMenu();
}
else if (optionA = 'V' || 'v')
{
volumeMenu();
}
else if (optionA = 'A' || 'a')
{
areaMenu();
}
else if (optionA = 'Q' || 'q')
{
printGoodBye();
}
}

void lengthMenu()
{
cout << "\tI = Inches to centimeters" << endl;
cout << "\tY = Yards to meters" << endl;
cout << "\tM = Miles to Kilometers" << endl;
cout << "Choose an option: ";
cin >> optionL;
if (optionL = 'I' || 'i')
{
inchesToCentimeters();
}
else if (optionL = 'Y' || 'y')
{
yardsToMeters();

}
else if (optionL = 'M' || 'm')

{
milesToKilometers();
}





// Lengths
inchesToCentimeters();
yardsToMeters();
milesToKilometers();

// Weights
ouncesToGrams();
poundsToKilograms();
tonsToKilograms();
// Volumes
pintsToLiters();
quartsToLiters();
gallonsToLiters();
// Areas
sqInchesToSqMillimeters();
sqFeetToSqMeters();
acresToSqMeters();

}
// Sub menus

void weightMenu()
{
cout << "\tO = Ounces to grams" << endl;
cout << "\tP = Pounds to Kilograms" << endl;
cout << "\tT = Tons to Kilograms" << endl;
cout << "Choose an option: " << endl;
cin >> optionW;
}
void volumeMenu()
{
cout << "\tP = Pint to liters" << endl;
cout << "\tQ = Quarts to liters" << endl;
cout << "\tG = Gallons to liters" << endl;
cout << "Choose an option: " << endl;
cin >> optionV;
}
void areaMenu()
{
cout << "\tI = Square inches to square millimeters" << endl;
cout << "\tF = Square feet to square meters" << endl;
cout << "\tA = Acres to square meters" << endl;
cout << "Choose an option: " << endl;
cin >> optionAr;
}

void inchesToCentimeters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void yardsToMeters()
{
number = enterData();
answer = (number * 0.9144);
printAnswer(number, " Yards ", answer, " Meters ");
mainMenu();
}

void milesToKilometers()
{
number = enterData();
answer = (number * 1.609344);
printAnswer(number, " Miles ", answer, " Kilometers ");
mainMenu();
}

//
void ouncesToGrams()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void poundsToKilograms()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void tonsToKilograms()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void pintsToLiters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void quartsToLiters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void gallonsToLiters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void sqInchesToSqMillimeters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void sqFeetToSqMeters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

void acresToSqMeters()
{
number = enterData();
answer = (number * 2.54);
printAnswer(number, " Inches ", answer, " Centimeters ");
mainMenu();
}

double enterData()
{
cout << "Enter your value: ";
cin >> number;
return number;
}

void printAnswer(double cTemp, string sTemp, double dTemp, string rTemp)
{
cout << endl;
cout << cTemp << sTemp << "= " << dTemp << rTemp << endl;
}

I'm not done but, I can't get it to pick other options in the menu. It only comes up with the Length menu.
@devinEleven

Main reason only the Length option comes up, is because your menu is wrong, I've edited it, and you should be able to use any menu option.

Remember, a single equal sign means assign value, whereas a double equal sign is for check equality value. Plus, you must do the same for checking the lowercase input as well.

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
void mainMenu()
{
cout << "L = Lengths" << endl;
cout << "W = Weights" << endl;
cout << "V = Volumes" << endl;
cout << "A = Areas" << endl;
cout << "Q = Quit" << endl;
cout << "Choose an option: ";
cin >> optionA;
if (optionA == 'L' || optionA == 'l')
{
lengthMenu();
}
if (optionA= = 'W' || optionA == 'w')
{
weightMenu();
}
else if (optionA == 'V' || optionA == 'v')
{
volumeMenu();
}
else if (optionA == 'A' || optionA == 'a')
{
areaMenu();
}
else if (optionA == 'Q' || optionA == 'q')
{
printGoodBye();
}
}


Another problem..

You haven't declared variable types. You have number = enterData() and answer = (etc.) but you don't say what their types are. You should declare them doubles.

1
2
double number = enterData();
double answer = (number * 2.54);


and
1
2
3
4
5
6
7
double enterData()
{
double number;
cout << "Enter your value: ";
cin >> number;
return number;
}
Last edited on
Awesome @whitenite1 !!! Thanks for your advice. I will try this.
C, and because of it a casual-enabled c++ compiler, will default int untyped variables.
if you use compiler flags to be strict with the language, it will not tolerate this which prevents bugs (here, you wanted a double!).
@whitenite1 Yep that did it! I had tried that before but, I must have had something wrong somewhere. I'm having trouble figuring out why I can't get my function to quit to work...
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
Write a program that will do simple conversations of lengths, weights, volumes, and areas. You
program will of course contain a main() that will call a function to start the program. The
function called by the main() will contain a menu that offers the user a number of main options
such as Lengths, Weights, Volumes, and Areas. Once the user selects an option the program
will proceed to another function which will give the user the sub options such as Inches to
centimeters, yards to meters and miles to kilometers. The main menu must loop until the user
indicates the user wishes to quit the program.

You must also write a print() function which takes in arguments needed to display the results
each time a conversion has taken place. Once a conversion is completed and displayed, the
user should be sent back to the main menu and asked if they wish to continue or would like to
select another option.
*/


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

double number;
double answer;
char optionA, optionL, optionW, optionV, optionAr, quit;

void printIntroduction();
void mainMenu();
void printQuit();
void printGoodBye();
void lengthMenu();
void areaMenu();
void volumeMenu();
void weightMenu();
void printAnswer();
// Lengths
void inchesToCentimeters();
void yardsToMeters();
void milesToKilometers();
// Weights
void ouncesToGrams();
void poundsToKilograms();
void tonsToKilograms();
// Volumes
void pintsToLiters();
void quartsToLiters();
void gallonsToLiters();
// Areas
void sqInchesToSqMillimeters();
void sqFeetToSqMeters();
void acresToSqMeters();


double enterData();
void printAnswer(double, string, double, string);

int main()
{
	printIntroduction();
	mainMenu();
	printQuit();
	printGoodBye();
	system("pause");
	return(0);
	
}

void printIntroduction()
{
	cout << "\t\tWelcome to Devin's simple measurment conversion tool." << endl << endl;
}

void mainMenu()
{
	cout << "Main Menu" << endl;
	cout << "\tL = Lengths" << endl;
	cout << "\tW = Weights" << endl;
	cout << "\tV = Volumes" << endl;
	cout << "\tA = Areas" << endl;
	cout << "\t\tChoose an option: ";
	
	cin >> optionA;
	if (optionA == 'L'|| optionA == 'l')
	{
	lengthMenu();	
	}
	else if (optionA == 'W'|| optionA == 'w')
	{
	weightMenu();
	}
	else if (optionA == 'V'|| optionA == 'v')
	{
	volumeMenu();
	}
	else if (optionA == 'A'|| optionA == 'a')
	{
	areaMenu();
	}
}

void lengthMenu()
{
	cout << "Lengths" << endl;
	cout << "\tI = Inches to centimeters" << endl;
	cout << "\tY = Yards to meters" << endl;
	cout << "\tM = Miles to Kilometers" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionL;
	
	if (optionL == 'I'|| optionL == 'i')
	{
		inchesToCentimeters();
	}
	else if (optionL == 'Y'|| optionL == 'y')
	{
		yardsToMeters();

	}
	else if (optionL == 'M'|| optionL == 'm')

	{
		milesToKilometers();
	}

}
// Sub menus

void weightMenu()
{
	cout << "Weights" << endl;
	cout << "\tO = Ounces to grams" << endl;
	cout << "\tP = Pounds to Kilograms" << endl;
	cout << "\tT = Tons to Kilograms" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionW;

	if (optionW == 'O' || optionW == 'o')
	{
	ouncesToGrams();
	}
	else if (optionW == 'P' || optionW == 'p')
	{
	poundsToKilograms();

	}
	else if (optionW == 'T' || optionW == 't')

	{
	tonsToKilograms();
	}
}
void printAnswer()
{
}
void volumeMenu()
{
	cout << "Volumes" << endl;
	cout << "\tP = Pint to liters" << endl;
	cout << "\tQ = Quarts to liters" << endl;
	cout << "\tG = Gallons to liters" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionV;
	if (optionV == 'P' || optionV == 'p')
	{
	pintsToLiters();
	}
	else if (optionV == 'Q' || optionV == 'q')
	{
	quartsToLiters();

	}
	else if (optionV == 'G' || optionV == 'g')

	{
	gallonsToLiters();
	}
}
void areaMenu()
{
	cout << "Areas" << endl;
	cout << "\tI = Square inches to square millimeters" << endl;
	cout << "\tF = Square feet to square meters" << endl;
	cout << "\tA = Acres to square meters" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionAr;

	if (optionAr == 'I' || optionAr == 'i')
	{
		sqInchesToSqMillimeters();
	}
	else if (optionAr == 'F' || optionAr == 'f')
	{
		sqFeetToSqMeters();

	}
	else if (optionAr == 'A' || optionAr == 'a')

	{
		acresToSqMeters();
	}
}

void inchesToCentimeters()
{
	number = enterData();
	answer = (number * 2.54);
	printAnswer(number, " Inches ", answer, " Centimeters ");
	mainMenu();
}

void yardsToMeters()
{
	number = enterData();
	answer = (number * 0.9144);
	printAnswer(number, " Yards ", answer, " Meters ");
	mainMenu();
}

void milesToKilometers()
{
	number = enterData();
	answer = (number * 1.609344);
	printAnswer(number, " Miles ", answer, " Kilometers ");
	mainMenu();
}

//
void ouncesToGrams()
{
	number = enterData();
	answer = (number * 28.349523);
	printAnswer(number, " Ounces ", answer, " Grams ");
	mainMenu();
}

void poundsToKilograms()
{
	number = enterData();
	answer = (number * 0.453592);
	printAnswer(number, " Pounds ", answer, " Kilograms ");
	mainMenu();
}

void tonsToKilograms()
{
	number = enterData();
	answer = (number * 907.18474);
	printAnswer(number, " Tons ", answer, " Kilograms ");
	mainMenu();
}

void pintsToLiters()
{
	number = enterData();
	answer = (number * 0.4731631);
	printAnswer(number, " Pints ", answer, " Liters ");
	mainMenu();
}

void quartsToLiters()
{
	number = enterData();
	answer = (number * 0.946326);
	printAnswer(number, " Quarts ", answer, " Liters ");
	mainMenu();
}

void gallonsToLiters()
{
	number = enterData();
	answer = (number * 3.785306);
	printAnswer(number, " Gallons ", answer, " Liters ");
	mainMenu();
}

void sqInchesToSqMillimeters()
{
	number = enterData();
	answer = (number * 645.16);
	printAnswer(number, " Square Inches ", answer, " Square Millimeters ");
	mainMenu();
}

void sqFeetToSqMeters()
{
	number = enterData();
	answer = (number * 0.09290304);
	printAnswer(number, " Square Feet ", answer, " Square Meters ");
	mainMenu();
}

void acresToSqMeters()
{
	number = enterData();
	answer = (number * (4.04688 * pow(10,3)));
	printAnswer(number, " Acres ", answer, " Square Meters ");
	mainMenu();
}

double enterData()
{
	number;
	cout << "\tEnter your value: ";
	cin >> number;
	return number;
}

void printAnswer(double cTemp, string sTemp, double dTemp, string rTemp)
{
	cout << endl;
	cout << cTemp << sTemp << "= " << dTemp << rTemp << endl;
	printQuit();
	cout << endl;
}

void printQuit()
{
	cout << "Would you like to continue? y/n: ";
	cin >> quit;
	cout << endl;
	if (quit == 'N' || quit == 'n')
	{
	void printGoodBye();
	}
	if (quit == 'Y' || quit == 'y')
	{
	void mainMenu();
	}
	 
}

void printGoodBye()
{
	cout << "\n\nGood bye, ya\'ll come back soon!\n\n" << endl;
}
Last edited on
@devinEleven
I'm having trouble figuring out why I can't get my function to quit to work..


Remove the void on lines 325 and 329. You are declaring a function, not calling them.

That should do it for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void printQuit()
{
	cout << "Would you like to continue? y/n: ";
	cin >> quit;
	cout << endl;
	if (quit == 'N' || quit == 'n')
	{
	void printGoodBye(); // Remove 'void'
	}
	if (quit == 'Y' || quit == 'y')
	{
	void mainMenu(); // Remove 'void'
	}
	 
}
@whitenite1

That helped bring up the Goodbye message but looped back to the main menu. I'll take a look at it and try to figure it out but, if you can find the issue let me know. I had it working befor but, I have made too many changes and I'm just not seeing it. Much appreciated!!
Last edited on
Is there something I should put in printGoodBye to make it terminate?
@devinEleven

You could #include <Windows.h> so you have access to a Sleep command, the add to the printGoodBye() function..

1
2
3
4
5
6
void printGoodBye()
{
	cout << "\n\nGood bye, ya\'ll come back soon!\n\n" << endl;
        Sleep(3000); // Pauses the screen for 3 seconds, giving time to read the above
        return 0; // exits the program
}
@whitenite1

Hmmm...it's complaining about printGoodBye returning a value. I took out the return,
now it waits for 3 seconds and prints the main menu.
I tried adding if(!quit) to mainMenu. it asks two times if I want to continue and then it exits.
Last edited on
@devinEleven

I messed with your code a little, placing a 'Quit' option in your mainMenu() function. If you do press 'Q' or 'q', the program asks for verification, then stops the program if you press 'Y' or 'y' or continues if you don't.

A bit easier by just requesting a quit in just one place in the program. Hope this helps.

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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include <Windows.h>

using namespace std;

double number;
double answer;
char optionA, optionL, optionW, optionV, optionAr, quit;

void printIntroduction();
void mainMenu();
char printQuit();
void lengthMenu();
void areaMenu();
void volumeMenu();
void weightMenu();
void printAnswer();
// Lengths
void inchesToCentimeters();
void yardsToMeters();
void milesToKilometers();
// Weights
void ouncesToGrams();
void poundsToKilograms();
void tonsToKilograms();
// Volumes
void pintsToLiters();
void quartsToLiters();
void gallonsToLiters();
// Areas
void sqInchesToSqMillimeters();
void sqFeetToSqMeters();
void acresToSqMeters();

double enterData();
void printAnswer(double, string, double, string);

int main()
{
	printIntroduction();
	mainMenu();
	Sleep(3000);
	return 0;

}

void printIntroduction()
{
	cout << "\t\tWelcome to Devin's simple measurement conversion tool." << endl << endl;
}

void mainMenu()
{
	char Quit;
	do
	{
		cout << "Main Menu" << endl;
		cout << "\tL = Lengths" << endl;
		cout << "\tW = Weights" << endl;
		cout << "\tV = Volumes" << endl;
		cout << "\tA = Areas" << endl << endl;
		cout << "\tQ - Quit the program" << endl << endl;
		cout << "\t\tChoose an option: ";

		cin >> optionA;
		if (optionA == 'L' || optionA == 'l')
		{
			lengthMenu();	
		}
		else if (optionA == 'W' || optionA == 'w')
		{
			weightMenu();
		}
		else if (optionA == 'V' || optionA == 'v')
		{
			volumeMenu();
		}
		else if (optionA == 'A' || optionA == 'a')
		{
			areaMenu();
		}
		else if (optionA == 'Q' || optionA == 'q')
		{
			Quit = printQuit();
		}
	}while(Quit !='Y' && Quit !='y');
	cout << "\n\nGood bye, ya'll come back soon!\n\n" << endl;
}

void lengthMenu()
{
	cout << "Lengths" << endl;
	cout << "\tI = Inches to centimeters" << endl;
	cout << "\tY = Yards to meters" << endl;
	cout << "\tM = Miles to Kilometers" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionL;

	if (optionL == 'I'|| optionL == 'i')
	{
		inchesToCentimeters();
	}
	else if (optionL == 'Y'|| optionL == 'y')
	{
		yardsToMeters();

	}
	else if (optionL == 'M'|| optionL == 'm')
	{
		milesToKilometers();
	}

}
// Sub menus

void weightMenu()
{
	cout << "Weights" << endl;
	cout << "\tO = Ounces to grams" << endl;
	cout << "\tP = Pounds to Kilograms" << endl;
	cout << "\tT = Tons to Kilograms" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionW;

	if (optionW == 'O' || optionW == 'o')
	{
		ouncesToGrams();
	}
	else if (optionW == 'P' || optionW == 'p')
	{
		poundsToKilograms();

	}
	else if (optionW == 'T' || optionW == 't')

	{
		tonsToKilograms();
	}
}

void printAnswer()
{
}

void volumeMenu()
{
	cout << "Volumes" << endl;
	cout << "\tP = Pint to liters" << endl;
	cout << "\tQ = Quarts to liters" << endl;
	cout << "\tG = Gallons to liters" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionV;
	if (optionV == 'P' || optionV == 'p')
	{
		pintsToLiters();
	}
	else if (optionV == 'Q' || optionV == 'q')
	{
		quartsToLiters();
	}
	else if (optionV == 'G' || optionV == 'g')
	{
		gallonsToLiters();
	}
}
void areaMenu()
{
	cout << "Areas" << endl;
	cout << "\tI = Square inches to square millimeters" << endl;
	cout << "\tF = Square feet to square meters" << endl;
	cout << "\tA = Acres to square meters" << endl;
	cout << "\t\tChoose an option: ";
	cin >> optionAr;

	if (optionAr == 'I' || optionAr == 'i')
	{
		sqInchesToSqMillimeters();
	}
	else if (optionAr == 'F' || optionAr == 'f')
	{
		sqFeetToSqMeters();
	}
	else if (optionAr == 'A' || optionAr == 'a')
	{
		acresToSqMeters();
	}
}

void inchesToCentimeters()
{
	number = enterData();
	answer = (number * 2.54);
	printAnswer(number, " Inches ", answer, " Centimeters ");
	//mainMenu();
}

void yardsToMeters()
{
	number = enterData();
	answer = (number * 0.9144);
	printAnswer(number, " Yards ", answer, " Meters ");
	//mainMenu();
}

void milesToKilometers()
{
	number = enterData();
	answer = (number * 1.609344);
	printAnswer(number, " Miles ", answer, " Kilometers ");
	//mainMenu();
}

//
void ouncesToGrams()
{
	number = enterData();
	answer = (number * 28.349523);
	printAnswer(number, " Ounces ", answer, " Grams ");
	//mainMenu();
}

void poundsToKilograms()
{
	number = enterData();
	answer = (number * 0.453592);
	printAnswer(number, " Pounds ", answer, " Kilograms ");
	//mainMenu();
}

void tonsToKilograms()
{
	number = enterData();
	answer = (number * 907.18474);
	printAnswer(number, " Tons ", answer, " Kilograms ");
	//mainMenu();
}

void pintsToLiters()
{
	number = enterData();
	answer = (number * 0.4731631);
	printAnswer(number, " Pints ", answer, " Liters ");
	//mainMenu();
}

void quartsToLiters()
{
	number = enterData();
	answer = (number * 0.946326);
	printAnswer(number, " Quarts ", answer, " Liters ");
	//mainMenu();
}

void gallonsToLiters()
{
	number = enterData();
	answer = (number * 3.785306);
	printAnswer(number, " Gallons ", answer, " Liters ");
	//mainMenu();
}

void sqInchesToSqMillimeters()
{
	number = enterData();
	answer = (number * 645.16);
	printAnswer(number, " Square Inches ", answer, " Square Millimeters ");
	//mainMenu();
}

void sqFeetToSqMeters()
{
	number = enterData();
	answer = (number * 0.09290304);
	printAnswer(number, " Square Feet ", answer, " Square Meters ");
	//mainMenu();
}

void acresToSqMeters()
{
	number = enterData();
	answer = (number * (4.04688 * pow(10,3)));
	printAnswer(number, " Acres ", answer, " Square Meters ");
	//mainMenu();
}

double enterData()
{
	number;
	cout << "\tEnter your value: ";
	cin >> number;
	return number;
}

void printAnswer(double cTemp, string sTemp, double dTemp, string rTemp)
{
	cout << endl;
	cout << cTemp << sTemp << "= " << dTemp << rTemp << endl;
	//printQuit();
	//cout << endl;
}

char printQuit()
{
	do
	{
		cout << "\nAre you sure you wish to end the program? y/n: ";
		cin >> quit;
		cout << endl;

	}while(quit != 'Y' && quit !='y' && quit != 'N' && quit !='n');
	return quit; 
}
I'll try that out. Thanks again!
It just produces an eror message that quit is being used without being initialized. I wonder if the res a way to convert quit into a 1 or a 0
Or an EOF command. I read over EOF but, I don't get how to apply it here.
or maybe if it counts printGoodbye and as long as printGoodBye < 1 I'm going to try this.
The instructions ask to have a continue question and then terminate if the user chooses to not continue.
I added an int countQuit and then added countQuit++ to printGoodBye and made mainMenu run while (countQuit < 1) It asks twice if I want to continue but at least it exits.
Last edited on
@devinEleven

This slight change in mainMenu(), will ask user if they wish to continue after each menu input.

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
void mainMenu()
{
	char Quit;
	do
	{
		cout << "Main Menu" << endl;
		cout << "\tL = Lengths" << endl;
		cout << "\tW = Weights" << endl;
		cout << "\tV = Volumes" << endl;
		cout << "\tA = Areas" << endl << endl;
		cout << "\t\tChoose an option: ";

		 cin >> optionA;
		if (optionA == 'L' || optionA == 'l')
		{
			lengthMenu();	
		}
		else if (optionA == 'W' || optionA == 'w')
		{
			weightMenu();
		}
		else if (optionA == 'V' || optionA == 'v')
		{
			volumeMenu();
		}
		else if (optionA == 'A' || optionA == 'a')
		{
			areaMenu();
		}
		// Ask if user wants to continue after each choice in menu
		Quit = printQuit();

	}while(Quit !='N' && Quit !='n');

	cout << "\n\nGood bye, ya'll come back soon!\n\n" << endl;
}


Changes to printQuit() is here..
1
2
3
4
5
6
7
8
9
10
11
12
char printQuit()
{
	char y_n;
	do
	{
		cout << "\nDo you wish to continue? y/n: ";
		cin >> y_n;
		cout << endl;

	}while(y_n != 'Y' && y_n !='y' && y_n != 'N' && y_n !='n');
	return y_n; 
}
Topic archived. No new replies allowed.