Computer Science Canada

help with numbers game

Author:  marz [ Mon May 05, 2003 4:44 pm ]
Post subject:  help with numbers game

Hi. I'm supposed to make a numbers game where it tells you the number of guesses you took to get the correct number. Now, here is what i have so far:
var number, guess : int
var number_of_guess : int :=1
colour(9)
randomize
randint (number, 1, 100)
loop
put "Enter a guess between 1 and 100: " ..
get guess
if guess = number then
colour(6)
put "WOW! You're right! good job"
if number_of_guess = 1 then
colour(4)
put "YAAAAA!!!!!!!! You got it in ", number_of_guess, " try!!"
elsif number_of_guess > 1 then
colour(17)
put "It took you ", number_of_guess, " tries to get this. Do better next time!"
end if
put "The number was ", number
end if
if guess > number then
colour(11)
put "Sorry! You're guess is too HIGH!!"
sound(100,100)
elsif guess < number then
colour(12)
put "Sorry! You're guess is too LOW!"
sound(1000,100)
end if
number_of_guess := number_of_guess + 1
exit when guess = number
end loop

ok, so now i have to modify the program so that the number of guesses taken so far is displayed on the screen.
Then i need to modify the program furthur by allowing the user to give up by entering a guess of -1. If the user gives up, then the number of guesses taken so far along with teh "hidden" number are to be displayed on the screen. Now, i dont understand a word of this... so if anyone could help me with the codes, it would be greatly appriciated! Very Happy Thanx SO MUCH!

Author:  Tony [ Mon May 05, 2003 4:54 pm ]
Post subject: 

first - plz use [code] and [/code] tags around your code. Easier to read.

Now, to count guesses, you just declear an int variable and initialize it to 0. Each time user takes a guess, you add +1 to it, so at the end you can just use "put counter" and it will tell you how many times you guessed.
(looking at your code I think you already have it done)

You know how you use a loop to keep on taking guesses? And "exit when" to exit when the guess is right? Just add another exit when guess = -1.

Author:  nate [ Mon May 05, 2003 6:48 pm ]
Post subject:  Marz

What skewl you go 2?

<span style="height:40; filter:glow(color=red, strength=5)">
-Nate

Author:  marz [ Wed May 07, 2003 8:15 am ]
Post subject: 

Yeah, what school do you go to? I go to school somewhere in Canada.
But, with the program, i only have it so far as to tell the number of guesses that you have taken altogether. I still dont know how to make it so that when they guess a number, it tells them, "you have guessed one". Please help!

Author:  Tony [ Wed May 07, 2003 9:17 am ]
Post subject: 

... you have it in your program already...

code:

if guess = number then
colour(6)
put "WOW! You're right! good job"


or do you mean display what number user has guessed? then its
code:

put "you have guessed ", guess


: