How to continue and exit program in void function

Nov 2, 2016 at 3:16pm
I'm wanting to continue from current function onto the next one using appropriate input, I am also wanting to exit the program entirely through appropriate input, to give you an idea this is what I currently have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  void Menu()
{
	system("cls");
	cout << "  MAIN MENU" << endl;
	cout << "To play, type 'Y'." << endl;
	cout << "Or to quit, type 'N'." << endl;
	string choice1;
	cin >> choice1;
	if (choice1 == "Y" || choice1 == "y")
	{
		//continue to next function
	}
	else if (choice1 == "N" || choice1 == "n")
	{
		//exit program
	}
}


I am aware that you cannot use return 0; within a void function in order to exit the program, I am wandering what possible ways I could go about doing this?
Nov 2, 2016 at 3:20pm
what about this in the else if:

exit(0);
Nov 2, 2016 at 3:38pm
Damn, I was trying to do something similar to this before, but it wasn't working, thank you so much.

I also have another problem if your able to help, i'm wanting to also do something similar to this but to re-run the program after appropriate input and also exit the program at the end of it through appropriate input, for an idea:
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
if (Win() == 'X')
		{
			system("cls");
			cout << X << " has Won!" << endl;
			cout << "Would you like to Play again, Y/N." << endl;
			string choice2;
			cin >> choice2;
			if (choice2 == "Y" || choice2 == "y")
			{
				return;
			}
			else if (choice2 == "N" || choice2 == "n")
			{
				return 0;
			}
		}
		else if (Win() == 'O')
		{
			system("cls");
			cout << O << " has Won!" << endl;
			cout << "Would you like to Play again, Y/N." << endl;
			string choice2;
			cin >> choice2;
			if (choice2 == "Y" || choice2 == "y")
			{
				return;
			}
			else if (choice2 == "N" || choice2 == "n")
			{
				return 0;
			}
		}
		//if players tie function
		else if (Win() == '/' && b == 9)
		{
			system("cls");
			cout << "It's a Tie!" << endl;
			cout << "Would you like to Play again, Y/N." << endl;
			string choice2;
			cin >> choice2;
			if (choice2 == "Y" || choice2 == "y")
			{
				return;
			}
			else if (choice2 == "N" || choice2 == "n")
			{
				return 0;
			}


(this is in main function) I understand how to exit it but I am not sure on how to loop it back round to the beginning of the program.
Last edited on Nov 2, 2016 at 3:40pm
Nov 2, 2016 at 4:41pm
If you want to loop back, you must have some kind of loop implementation, perhaps a while loop?
Topic archived. No new replies allowed.