I just started learning C++, and after doing some smaller programs, I decided to make a blind hack at a crude RPG type game (a thing I like to do with new programming languages). There are some things that are happening that I can't understand and I need your help. Here is the code (some pieces omitted):
Code:
#include <iostream>
#include <string>
using namespace std;
int u_level;
int u_exp;
int u_hp;
//other global variables named
//nothing was omitted in following function
void Startup ()
{
cout<<"It has begun\n";
system("Pause"); //pause works here
cout<<"Did you doubt it?\n";
system("Pause"); //pause works here
system("cls");
int selection;
cout <<"1. New Game" <<"\n";
cout <<"2. Load Game" <<"\n";
cout <<"3. Exit" <<"\n";
cout <<"Please enter the number of your selection: ";
cin >> selection
cout << selection //added for debugging, does NOT out put the variable
system("PAUSE") //added for debugging, does NOT pause
switch (selection) {
case 1:
cout << "Your in case 1"; //added for debugging, does NOT display
system("Pause"); //added for debugging, does NOT pause
break;
case 2:
//SET UP SAVING SYSTEM
break;
case 3:
cout << "Thanks for playing!" <<"\n"; //displayed breifly
system("Pause"); //Pause does not work
system("exit");
break;
default:
cout<< "Enter a number listed above.";
}
}
int main()
{
Startup ();
cout<<"It has been a while young one\n";
cout<<"my memory is beginning to fade.\n";
system("Pause");
cout<<"What is your name again?";
//more lines follow
}
So, whenever I run the program void Startup () is automatically called, even when I comment out the definition line AND the line where it is called in int main(). Also, as commented above, several of the pauses don't work. My desired result is for the function to be called, run, and if the user selects 1 then the program will continue in int main(), and if they select 3, then it will display Thanks for playing!, pause and exit. But, when the user selects 1 the program closes with no text being displayed (as commented) And, when the user selects 3 the program will briefly display the text, then close. So, why is it happening like it is? All thoughts and opinions about the code and my question are greatly appreciated. Also, if there any questions about what I am asking, or you want to see more code, just ask.
thanks in advance
---axehero