
-----------------------------------
ssr
Sat Oct 23, 2004 7:42 pm

bugged guessing game
-----------------------------------
hello ever1, I just made a guessing game,  :D however, there is a bug in it, :(  that is whenever you guess the number right the first time, it asks you twice if you want to continue, it is caused by the loop, I think. :oops:  can any1 help me? :?:

-----------------------------------
Delos
Sat Oct 23, 2004 10:16 pm


-----------------------------------
Ok...your code really is buggy.

You have a lot of redundancy in it, for example

if strintok (answer) = true then


You don't need the "= true" part.  strintok is a boolean function, thus it returns true/false as it is...


count := count + 3


If you're resetting 'count', just use "count := 3" instead.

And then again, why you have 'count' is a mystery, you're using a for loop thus the number of times it loops is already counted.

When an answer is guessed correctly, before the count extinguishes, one is prompted with the desicion to exit or not.  This doesn't actually work...if you want to exit, it still keeps you in the main loop.

My suggestion for this is to reconsider how you've structured your programme.  If you're going to use 'count' then don't bother with the for loop.  It adds an extra level of unnecassary complexity to your programme that could quite simply be made without it.

-----------------------------------
Hikaru79
Sat Oct 23, 2004 11:42 pm


-----------------------------------
Here's a streamlined and WORKING version of your code. I rewrote it but tried to use as much recycled code from your program as I could. All I ask is that if you are handing this code in you CAREFULLY look it over and make sure you UNDERSTAND my code. :) Good luck!

var answer : string
var randnum : int
var guess : int

loop
    randint (randnum, 1, 10)
    put "I've selected a number between 1 to 10."
    put "You have three chances to guess it right!  " ..
    for count : 1 .. 3
        get answer
        if strintok (answer) then
            guess := strint (answer)
        else
            put "Please input an integer:  " ..
        end if
        if guess = randnum then
            put "You are so lucky! It is ", randnum, "!"

        elsif guess > randnum then
            put "It's too big. You have ", 3 - count, " tries left!"
        else
            put "It's too small. You have ", 3 - count, " tries left!"
        end if
    end for
    if guess not= randnum then
        put "You have failed. The answer was ", randnum, "!"
    end if
    put "Do you want to give it another shot? (yes/no)  " ..
    get answer
    if answer = "yes" or answer = "Yes" or answer = "y" or answer = "Y" then
        cls
    else
        exit
    end if
end loop


-----------------------------------
Andy
Sun Oct 24, 2004 1:28 pm


-----------------------------------
err ur code would crash if they give an invalid input
