Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
I'm sorry to disturb you...
There's this little game I'm developing and I'm stuck.
So the game is about guessing a random number and I want to put a timer to see how long did the user to guess the number.
Here's the code for the timer:
[code]Procedure Timer ;
time := 0 ;
While a <> b do
Writeln ('Seconds: ',time,'') ;
Delay (1000) ;
Inc (time) ;
"a" is the input number and "b" is the randomized number.
The problem is that the program keeps repeating the delay of 1 second and it doesn't let me input a number.
I thought on executing the main program and the procedure at the same time but I guess there is another way of doing it.
Here's the code for the rest of the game:
[code]Program Guess_the_number ;
Uses crt ;
var a, b, time : Integer ;
b := 1 ;
b := random (100) ;
Writeln ('Write a number between 1 and 100:') ;
Readln (a) ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
You guys have any ideas?
0 · ·