I was wondering if there is a substitute for a goto statement at the
1 2 3 4 5 6 7
if(players_input=="inventory"){
void inventory();
//need something for here
}
elseif(players_input=="stats"){
int playerStats();
//need something for here
as after it has been to inventory or playerStats I would like it to return to the top of "string input" function.
I can use goto but I have heard that it is a bad practice so if there is another way I will use that instead.
//gets players input then goes to inventory/stats/quits or returns move to story
string input(bool Forward, bool Left, bool Right, bool Backwards){
//goto here
if(Forward)
string Forward2="forward";
if(Left)
string Left2="left";
if(Right)
string Right2="right";
if(Backwards)
string Backwards2="backwards";
//preferably here.
cout<<"Enter the corresponding word to do the following: \n";
cout<<"If you would like to move please enter:\t 'move'\n";
cout<<"If you would like to see your inventory please enter:\t 'inventory'\n";
cout<<"If you would like to see your statistics please enter:\t 'stats'\n";
cout<<"If you would like to quit then please enter:\t 'quit'\n\n";
cout<<"Input: ";
cin>>string players_input;
while(players_input!="inventory" || players_input!="stats" || players_input!="quit" || players_input!="move"){
cout<<"You have entered a invalid command. Please re-enter: "
cin>>players_input;
}
if(players_input=="inventory"){
void inventory();
//need something for here
}
elseif(players_input=="stats"){
int playerStats();
//need something for here
}
elseif(players_input=="quit"){
return ("quit")
}
}
(i haven't compiled it yet so there may be a few mistakes and it is not finished yet.) Thank you for any advice.