Jump to content

Recommended Posts

Posted

I was trying to make a 'Guess the Number' program in computercraft, and I came up with this code:

disp_hint = "hint"

write("Enter a number!")

number = read()

write("Enter a hint for the number!")

hint = read()

 

term.clear()

term.serCursorPos(1,1)

repeat

    print("Guess the number, or type hint for a hint!")

    guess = read()

    if guess == number then

        print("You're Right!")

        end

    elseif guess == disp_hint then

        print("..hint..")

   

    else

        print("Nope!")

 

    end

until guess == number

exit()

I get the error "bios:206: [string "guessthenumber.lua"]:15: 'until' expected (to close 'repeat' at line 9)" I know its a problem with the loop, but I cant figure out how to solve it. Will someone be my wife and point out the problems?

Posted

Try:

disp_hint = "hint"

write("Enter a number!")

number = tonumber(read())

write("Enter a hint for the number!")

hint = read()

 

term.clear()

term.serCursorPos(1,1)

repeat

    print("Guess the number, or type hint for a hint!")

    guess = tonumber(read())

    if guess == number then

        print("You're Right!")

    elseif guess == disp_hint then

        print("..hint..")

 

    else

        print("Nope!")

 

    end

until guess == number

exit()

I remove the "end" at line 14 and add "tonumber()"this is optional just makes it a real Integer:D.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...