please how do i go about calling in between functions without using goto........for example if i have done some codings and after operation i want to ask if the user wants to perform another function.
something like this below:
cout << "Thank you playing this game.\n";
goto end
end:
{
cout <<"Do you want to play another game: (y / n):";
cin >>d;
if (d == 'y')
{ cout << "\n\n";
return main();
}
}
how do i avoid using ""goto"" as in above?????...linking the main function and end??
It sounds like this job you gave here is a job for a good-old loop (No functions needed! Can you believe it?). I recommend do-while loop with the condition (d == 'y').
Thanks for the replies but what i mean is that the statement below
cout << "Thank you playing this game.\n";
goto end
is one of the nested branches of an if-else loop that has about 16 branches and i need to refer to the end function on all of these branches in case the user wants to return to the main function to perform another operation....How do i go about it
#include<iostream>
usingnamespace std;
bool askuser();
int main(){
//your codes
cout << "Thank you playing this game.\n";
if(askuser()){
//play another game
}
//else exit.
return 0;
}
bool askuser()
{
char d;
cout <<"Do you want to play another game: (y / n):";
cin >>d;
if (d == 'y'){
returntrue;}
else
{
returnfalse;
}
}
@Frank : Do you mean The Statement Thank you playing this game is printed every time user has finished a game ??
@Frank && @Computer : I'm sorry, because i'm not perfect in English, so sometimes i can't understand problems perfectly, so Sorry all ..