小编JL1*_*123的帖子

Lua elseif无法正常工作

当我尝试使用时elseif,它不起作用.对于下面的代码,无论用户输入哪个数字,运行的唯一代码是if语句下的代码.

io.write("do you want to convert from celsius to farenheit (1), or the other way around (2)?")
pref = io.read()
if pref == 1 then
  io.write("Hi there! what's your temperature in celsius? ")
  local cel = io.read()
  far = (cel*1.8+32)
  io.write("That temperature in farenheit is: " .. far)
elseif pref == 2 then
  io.write("Hi there! what's your temperature in farenheit? ")
  local far = io.read()
  cel = ((far-32)/1.8)
  print("That temperature in celsius is: " .. cel)
end
Run Code Online (Sandbox Code Playgroud)

lua if-statement

3
推荐指数
1
解决办法
138
查看次数

标签 统计

if-statement ×1

lua ×1