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.
#include <iostream>
usingnamespace 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" ;
}