unexpected repetition

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

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);
		}
		else if(q2 == 2){//dont order book
		cout<<"ok nevermind\n";
		}
}

else if( 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
else if(travel == "store"){
	cout<<"you walk into the store\n1)Ask for manager\n2)look for "<< goal << " on shelf";

}

else if(travel == "life"){
cout<<"you walk into the store\n1)Ask for manager\n2)look for "<< goal << " on shelf";

}

}.
line 26 sleep(1000);
what header did you use for that syntax
I am trying to compile it in my compiler
Last edited on
i used time.h

void sleep(long d)
{
clock_t start=clock();
while(clock() - start < d); ///loop until time's up
}
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
ok i will try
that
Topic archived. No new replies allowed.