
-----------------------------------
marz
Mon May 05, 2003 4:44 pm

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!  :D Thanx SO MUCH!

-----------------------------------
Tony
Mon May 05, 2003 4:54 pm


-----------------------------------
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.

-----------------------------------
nate
Mon May 05, 2003 6:48 pm

Marz
-----------------------------------
What skewl you go 2?


-Nate

-----------------------------------
marz
Wed May 07, 2003 8:15 am


-----------------------------------
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!

-----------------------------------
Tony
Wed May 07, 2003 9:17 am


-----------------------------------
... you have it in your program already...


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

put "you have guessed ", guess

