problem with set of code do-while

i have a problem with this set of code because i should be able to end the program when the person guess the right answer (should say you win and ask the user to repeat the program) or should keep guessing until time is 0 then it should show a message saying game over the correct answer is XXX and the same ask user to repeat program. i do not know how to close the while..



//starting the program with the input
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
51
52
cout << "Enter value for prize: ";
cin >> price;
start_time=time(0);

number2 = rand() % 500 + 500;

//looping higher, lower and you win
do
{
if (price<number2)
{
gout << setPos (155, 360) << "HIGHER" << endg;
}
else if (price>number2)
{
gout << setPos (155,360) << "LOWER" << endg;
}
else if (price==number2)
{
gout << setPos (155, 360) << "!!!!!!YOU WIN!!!!!!" << endg;
}

current_time = time(0);
remain_time = 30 - (current_time - start_time);

gout << setPos(155, 380) << "Time Remaining " << remain_time << " secs" << endg;

cout << "Enter value for prize: ";
cin >> price;


if (remain_time<=0)
{
gout << setPos (155, 360) << "GAME OVER" << endg;
gout << setPos (155, 400) << "correct price" << number2 << endg;
}

}while ((price!=number2) || (remain_time>0));



//Ask user to run program again
cout << "Run program again? (y/n): ";
cin >> repeat;

clearGraphics();

}while ( (repeat == 'y') || (repeat == 'Y') );


return 0;
} 
it is not stopping whenever time is 0 it keeps counting -1 -2 -3 and if the answer is right keep inside the while
Topic archived. No new replies allowed.