int CallInfo()
{
string sClientName;
int sClientChoice;
cout << "Hello, what's your name?" << endl;
cin >> sClientName;
cout << "Hello " << sClientName << endl;
cout << "Enter either 1 to exit program or 2 to go back to main menu" << endl;
cin >> sClientChoice;
if (sClientChoice == 1)
{
system("exit");
}
elseif (sClientChoice == 2)
{
//RETURN TO INT MAIN SOMEHOW??
}
}
int main()
{
int sClientAge;
cout << "Hello" << endl;
cout << "How old are you?" << endl;
cin >> sClientAge;
if (sClientAge >= 18)
{
CallInfo();
}
else
{
cout << "Sorry, you're not old enough" << endl;
Sleep(2000);
system("exit");
}
}
Please take in mind that this is just a quick example to get my point across hence why they're no includes xD
You are not using the return value of the function though. Maybe it's better if you declare it as returning void. A void function can use the return keyword with no arguments.
You should think of a function as something that does some specific task. When the task is finished the function returns. The function should not have to care about where it returns to. It just returns to the code that called the function.
A function will automatically return when the function ends. If you want to end the function earlier and/or you want to return a value from the function you can use a return statement. To return from a void function you just do return;. If the function has a return type, other than void, you add the value that you want the function to return after, so if you want CallInfo() to return the value 5 you write return 5;.
If you use return 0; in function CallInfo(), the program definitely does return to main.
It will return to main() at line 38.
When it reaches the closing brace at line 40, execution continues at line 49.
Then at line 50, the end of function main() is reached.
So if you want something else to happen, you need to add code to make it happen.
Sounds like you missed the point of functions. When a function finishes, either by reaching a return or because there is no more code to execute, the program flow goes back to where that function was called from. It's that simple.
An aside on what to call functions:
What you call an "int" isn't an int. Where you say
from another int?
we would say "from a function". An int is a data type. It's not a function. What you call "the int main" is the function named main.