Hello guys , i recently started programming in C++ , and i am trying to create a text-based RPG in prompt console ...

what my problem is that i have my main function , calling one other function name infomisc , in infomisc function it let you choose , 1. create character and 2. exit program , now i created a switch for this to work :

switch( info1 )
{
case 1:
	{
	character();
	}
	break;
case 2:
	{
	exitprog();
	}
	break;
default:
cout << "\n Invalid number inserted";
}

this , till here its ok , isnt it ?

i created int character(){} and int exitprog(){} , in character i didnt add anything yet , in exitprog i added exit(); , it gives me error , how can i make it exit the program?

Regards

exit() isn't a real great way to end your program, but I can't give you a better alternative without seeing your code. Could you post the entire code if it's not to long?

Here it is :

#include <iostream>
#include <string>

int welcome();
int infomisc();
int exitprog();
int character();

using namespace std;



int main()
{
  cout << "Welcome to Arhes v1.0 , a text-based RPG\n";
  cout << "\n";
  infomisc();
  cin.get();
  return 0;
}

int infomisc()
{
	int info1;
	cout << "Please choose what you want to do : \n";
	cout << "1. Create new character [Press 1]\n";
	cout << "2. Exit program         [Press 2]\n\n";
	cin >> info1;
	cin.get();
	return 0;

switch( info1 )
{
case 1:
	{
	character();
	}
	break;
case 2:
	{
	exitprog();
	}
	break;
default:
cout << "\n Invalid number inserted";
}

}

int exitprog()
{
	cin.get();
	return 0;
}

int character()
{
 cout << "Choose your class\n";
	cin.get();
	return 0;
}

modified a bit

fixed

You should remove the return 0; in your infomisc() function. The switch will never be reached this way.

And how about you don't call the function exitprog(), but just return -1; Then you could put something like this in the main:

if (infomisc() == -1) {
    //exit your program here, for example:
    return 0;
} else {
    // don't quit and do other stuff
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.