lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, I recently built a sample code for calculating reciprocal winds for flight simulation purposes. I want to limit user input to numbers from 0-359 inclusive. Nothing like 360 should be entered by user. How can I do this?

local line
repeat
print("Input wind heading: ");
line = io.read()     -- read a line
    n = tonumber(line)   -- try to convert it to a number
    k = tonumber(line)
    k = 180-n
    if n > 180 then
      print("Reciprocal heading is: ",-k)
    elseif n < 180 then
      print("Reciprocal heading is: ", n+180) 
      else n = 180
      print ("are you kidding me?")
    end  
    print("do you want to convert again? y/n?")
    line = io.read()
until line ~= "y"
print("Goodbye")

Also how can I input this into the source code executable to run it? If I press enter after the first line it just stops at local line.

Thanks in advance
Adel