私は非常に基本的な電卓プログラムの作業を始めたばかりで、計算が完了した後、プログラムを開いたままにしておくことができません。io.read() が機能していないようです。私のコードは次のとおりです。
promptmethod = "Would you like to use addition, subtraction, multiplication, or division?"
promptnumber1 = "Enter a number:"
promptnumber2 = "Enter another number:"
anotherprompt = "Would you like to make another calculation?"
print(promptmethod)
usermethod = io.read("*line")
print(promptnumber1)
number1 = io.read("*number")
print(promptnumber2)
number2 = io.read("*number")
if usermethod == "addition" then
answer = number1 + number2
stringanswer = "Your calculation is " .. number1 .. " + " .. number2 .. " = " .. answer
elseif usermethod == "subtraction" then
answer = number1 - number2
stringanswer = "Your calculation is " .. number1 .. " - " .. number2 .. " = " .. answer
elseif usermethod == "multiplication" then
answer = number1 * number2
stringanswer = "Your calculation is " .. number1 .. " × " .. number2 .. " = " .. answer
elseif usermethod == "division" then
answer = number1 / number2
stringanswer = "Your calculation is " .. number1 .. " ÷ " .. number2 .. " = " .. answer
else
error("Invalid operation or values.")
end
print(stringanswer)
io.read()
なぜこれが起こるのか誰にも分かりますか?ありがとうございました!