[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Luai problem
- From: Sean Conner <sean@...>
- Date: Fri, 7 Jul 2017 04:01:00 -0400
It was thus said that the Great Paul Krahn once stated:
> Hello there,
>
> So this is my first "lua mailing list" post and I got a problem with my lua code
>
> I just started coding luai yesterday and tutorials won't give me answers to my case.
>
> So, in this scenario, I want the code to first ask the user for his name and age. Then, depending the age is either below or above (or exact) 18, it should print different text lines.
>
> The problem is, it prints the line "Hello, .. myName" but everything after doesn't compile...
>
> As said, it's my first code and still trying to improve my knowledge of lua/luai. Any further improvements would also be appreciated.
>
> Here's the code:
>
> io.write("Please enter your name here: ")
> local myName = io.read( )
> io.write("Please enter your age here: ")
> local myAge = io.read( )
>
> print ("Hello, " .. myName)
>
> if myAge < 18 then
> print ("\nwe're sorry but you must be 18 or above to continue")
> end
> if myAge >= 18 then
> print ("\nYou are allowed to continue without limitations")
> end
io.read() returns a string. You need to convert myAge to a number before
you can compare it to 18. Try this:
local myage = io.read( )
myage = tonumber(myage)
-spc