skip to function?

I am somewhat new to c++. I been using gaming programming(level editors, scripts, etc.) for some time but i've recently taken a c++ prgramming class in highschool, (since august). and i've understood mostly everything we've been taught. But i'm trying to move ahead and create a small prgram (a text based game) and in class we havent learned more ,functions I believe, then int main(). I've taken time and gone online to learn void blabla(). in my program, im running a while() loop and it runs continuously using a switch inless you choose 13 as the number. (and yes I know switches can run on characters, ect, i do want to use a number (haha). this is what I have so far
1
2
3
4
5
6
7
8
9
10
11
	case 13:
			{
		cout << "You chose 13, which is not a choice, but its also a unlucky number, you may move on " << endl;
		cout << endl;
		whilenum = 2;
		trys = 0;
		system ("PAUSE");
		system ("CLS");
		part2();
			}
		break;


note: part2() is the void funct. down below, and i'm trying to skip to it., also note: my computer needs the system ("PAUSE") or it'll just end without prompting user to press enter to continue. Can anyone point me to a tutorial on skipping to line. I've read about the unfavored goto command, but am refraining from using it.
Last edited on
Uhm as a fellow c++ beginner I beleive I might be able to help you :D

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

//prototype
void thirteen();

int main()
{
	int x;
	char tempChar;
	do 
	{
		cin>> x;
			
//optional, but might wanna observe it , 'cause came out quite usefull to me today :D
//Makes program not go haywire when something else but a number is entered
//-------------------------------------------
		if (cin.fail())	 
		{
			cout<< "\nPlease type a number\n";
			cin.clear();
			tempChar = cin.peek();		
			cin.ignore(1);
		}
//-------------------------------------------

	}
	while (x != 13);
	x==13? thirteen(): cout << "try again ^^\n"; //using if statement here, but I assume you can make it a switch anytime ^^
	
	cin.get();//replaces your system commands:)
	cin.get();
	return 0;
}

void thirteen()
{
cout << "woohoo its 13\n" ;
}


Hope it helped ^^
Topic archived. No new replies allowed.