Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 bugged guessing game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ssr




PostPosted: Sat Oct 23, 2004 7:42 pm   Post subject: bugged guessing game

hello ever1, I just made a guessing game, Very Happy however, there is a bug in it, Sad 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. Embarassed can any1 help me? Question


unfinished guessing.t
 Description:
help me with this game

Download
 Filename:  unfinished guessing.t
 Filesize:  918 Bytes
 Downloaded:  130 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Oct 23, 2004 10:16 pm   Post subject: (No subject)

Ok...your code really is buggy.

You have a lot of redundancy in it, for example
code:

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...

code:

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




PostPosted: Sat Oct 23, 2004 11:42 pm   Post subject: (No subject)

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. Smile Good luck!

code:
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




PostPosted: Sun Oct 24, 2004 1:28 pm   Post subject: (No subject)

err ur code would crash if they give an invalid input
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: