How to loop back to main menu?

closed account (9ypNhbRD)
Okay I made this program which basically has a menu and will have different options given at the menu. The user can choose to run different parts of the program for example the calculator. What I would like is for the user to be able to run different parts of the program and then go back to the menu. Also, as soon as you do something in the calculator or any other parts of the program the program closes. How do i keep it running?

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
#include"stdafx.h" 
#include<iostream>
#include<math.h>
using namespace std;

int calculator()
{
	int number1, number2, result, z;
	double PI = 3.1416;

	cout << " _____________________________________________________ " << endl;
	cout << "|                      Calculator                     |" << endl;
	cout << "|_____________________________________________________|" << endl;
	cout << "|  ____   ____   ____   |  ____   ____   ____   ____  |" << endl;
	cout << "| |sin7| |cos8| |tan9|  | |  1 | | 2  | |  3 | |+(1)| |" << endl;
	cout << "| |____| |____| |____|  | |___ | |____| |____| |____| |" << endl;
	cout << "|  _____  _____  ____   |  ____   ____   ____   ____  |" << endl;
	cout << "| |e^x11||sqr10||Ln 6|  | |  4 | | 5  | |  6 | |-(2)| |" << endl;
	cout << "| |_____||_____||____|  | |___ | |____| |____| |____| |" << endl;
	cout << "|  ____                 |  ____   ____   ____   ____  |" << endl;
	cout << "| |Log5|                | |  7 | | 8  | |  9 | |*(3)| |" << endl;
	cout << "| |____|                | |____| |____| |____| |____| |" << endl;
	cout << "|                       |         ____          ____  |" << endl;
	cout << "|                       |        | 0  |        |/(4)| |" << endl;
	cout << "|                       |        |____|        |____| |" << endl;
	cout << "|_____________________________________________________|" << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "Please Pick the number of the operation you wish to use" << endl;
	cin >> z;
	cout << "" << endl;
	cout << "" << endl;

	switch (z)
	{
	case 1:
		cout << "Type in first number.\n" << endl;
		cin >> number1;
		cout << "Type in second number.\n" << endl;
		cin >> number2;
		result = number1 + number2;
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;



	case 2:
		cout << "Type in first number.\n" << endl;
		cin >> number1;
		cout << "Type in second number.\n" << endl;
		cout << "" << endl;
		cin >> number2;
		result = number1 - number2;
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 3:
		cout << "Type in first number.\n" << endl;
		cin >> number1;
		cout << "Type in second number.\n" << endl;
		cin >> number2;
		result = number1 * number2;
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 4:
		cout << "Type in first number.\n" << endl;
		cin >> number1;
		cout << "Type in second number.\n" << endl;
		cin >> number2;
		result = number1 / number2;
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 5:
		cout << "Type in number.\n" << endl;
		cin >> number1;
		double param, result;
		param = number1;
		result = log10(param);
		cout << "" << endl;
		printf("log(%f) = %f\n", param, result);
		system("pause");
		return 0;

	case 6:
		cout << "Type in number.\n" << endl;
		cin >> number1;
		result = log(number1);
		cout << "" << endl;
		cout << "Ln(number)=" << result << endl;
		system("pause");
		return 0;


	case 7:
		cout << "Type in Angle.\n" << endl;
		cin >> number1;
		result = sin(number1*PI / 180);
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 8:
		cout << "Type in a angle in degrees.\n" << endl;
		cin >> number1;
		result = cos(number1*PI / 180);
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 9:
		cout << "Type in a angle in degrees.\n" << endl;
		cin >> number1;
		result = tan(number1*PI / 180);
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 10:
		cout << "Type in a number.\n" << endl;
		cin >> number1;
		result = sqrt(number1);
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;

	case 11:
		cout << "Type in first number.\n" << endl;
		cin >> number1;
		result = exp(number1);
		cout << "" << endl;
		cout << result << endl;
		system("pause");
		return 0;


	default:
		cout << "Please pick one of the given options" << endl;
		system("pause");
		return 0;
	}
}

int info()
{
	int a;
	cout << "please type in your age" << endl;
	cin >> a;
	cout << "your age is" << a << endl;
	system("pause");
	return 0;


}

int main() {
	char choice;
	
	cout << " _______________________ " << endl;
	cout << "|         Menu          |" << endl;
	cout << "|_______________________|" << endl;
	cout << "|  __________________   |" << endl;
	cout << "| | A for Calculator |  |" << endl;
	cout << "| |__________________|  |" << endl;
	cout << "|  __________________   |" << endl;
	cout << "| |   B for Arrays   |  |" << endl;
	cout << "| |__________________|  |" << endl;
	cout << "|  __________________   |" << endl;
	cout << "| |   C for info     |  |" << endl;
	cout << "| |__________________|  |" << endl;
	cout << "|_______________________|" << endl;
	
	cin >> choice;
	if (choice == 'a') calculator();
	else if (choice == 'c') info();
	else cout << "invalid choice\n";
	return 0;
}


Last edited on
Please use code tags when posting code, to make your code readable:

http://www.cplusplus.com/articles/z13hAqkS/
closed account (9ypNhbRD)
done
closed account (9ypNhbRD)
can someone help ? :(
Topic archived. No new replies allowed.