after writing this while loop everything works fine the first time it runs, however when it goes around again it prints the line "you find yourself standing in the middle of village".etc twice but i only want it to say it once.i do not know why it does that and help would be greatly appreciated.
string name;
string gender;
bool gotgoal = false;
string goal;
string travel;
int q1;
int q2;
int q3;
int q4;
while(!gotgoal){
travel = "defualt";
cout << "you find yourself standing in the middle of a village\n Where do you wish to travel?\nthe library\nthe general store\nthe postoffice\nthe music store\nthe church\nthe restaurant \n";//<---- repeated text
getline(cin, travel);
if(travel == "library" || travel == "The library" || travel == "Library" || travel == "the library"){//library
cout<<"you walk into the library and are immediatly greeted by the librarian\n1)do you have any books on "<< goal << "?" <<"\n"<<"2)do you know where i can find "<< goal <<"?\n";
cin>> q1;//first library question
if( q1 == 1 ){//do you have any books on...
cout<<"Not at the moment sorry, I can order one in if you want?\n1)sure\n2)no thanks\n";
cin>> q2;
if(q2 == 1){//order book
cout<<"No problem I'll contact you when it arrives\n";
sleep(1000);
cout<<"book ordered!\n";
sleep(500);
}
elseif(q2 == 2){//dont order book
cout<<"ok nevermind\n";
}
}
elseif( q1 == 2 ){
cout<<"err I think i heard the general store owner talking about that the other day why dont you talk to him\n";
}
}//library end
elseif(travel == "store"){
cout<<"you walk into the store\n1)Ask for manager\n2)look for "<< goal << " on shelf";
}
elseif(travel == "life"){
cout<<"you walk into the store\n1)Ask for manager\n2)look for "<< goal << " on shelf";
}
}.
ah its a function, I use capital letters for functions so that I can distinguish them
void Sleep(long d)
to solve the repetition of ur problem I will make a bool stillstanding=true
and before the while loop I will ask if(stillstanding){//the while loop body}
and inside the if statements and else ifs I will end it with stillstanidng=false