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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...