Trouble with "Back" in a menu

Im trying to create a menu for conversions. Ive created 2 sub menus, but the "back" for the 1st submenu continues to loop and doesnt allow me to return to the main menu. IF what im saying doesnt make sense, look at my code.

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
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int index;
	double input1, input2, output;
	bool quit, back, back2;

	do 
	{
		cout << "0. Quit\n";
		cout << "1. Units Conversion\n";
		cout << "2. Four Operations\n";
		cout << "3. Math Functions\n";
		quit = false;
		cin >> index;
		switch (index)
		{
		case 0:
			quit = true;
			break;
		case 1:
			do
			{
				cout << "0. Back to Previous Menu\n";
				cout << "1. Length\n";
				back = false;
				cin >> index;
				switch(index)
				{
				case 0: 
					back2 = true;
					break;
				case 1:
					do
					{
						cout << "0. Back\n";
						cout << "1. From Inches to Meters\n";
						cout << "2. From Meters to Inches\n";
						back = false;
						cin >> index;
						switch (index)
						{
						case 0:
							back2 = true;
							break;
						case 1:
							cout << "Enter a Length:\n";
							cin >> input1;
							output = input1 * 25.4 / 1000;
							cout << "It equals" << output << " m\n";
								break;
						case 2:
							cout << "Enter a Length:\n";
							cin >> input2;
							output = input2 * 39.3701;
							cout << "It equals" << output << " in\n";
								break;
						}
					}while (back2 != true);
					break;
				}
			}while(back != true);
			break;
		
		default:
			break;
		} 
	}while(quit != true);
		
	system("pause");
	return 0;
	
}	
			
  
On line 34: I'd say that it should be back2
Last edited on
Topic archived. No new replies allowed.