Posted 11 June 2013 - 01:40 PM
I'm having issues with this really simple program I made
it's a simple program that ask you the sum of 2 random chosen nubers
the problem is that,whatever the answer I put,it says wrong,even if it's correct,I don't know what is wrong with this code,it should works,but it look like that it can't compair the user answer with "z" wich is the correct answer,I even tried to make it write "z" (that's why there is a "print(z)" on Ln 6) and it still do that even when answer match "z"
I already know that it's possible to make the computer compair a hand-written answer with a variable (like in password programs) but it seems to don't work with random numbers
is it possible to fix it,if yes,how?
thanks
x=math.random(1,9)
y=math.random(1,9)
write(x.."+"..y.."=")
answer=read()
z=x+y
print(z)
if answer==z then
print("NICE!")
else print("wrong")
end
it's a simple program that ask you the sum of 2 random chosen nubers
the problem is that,whatever the answer I put,it says wrong,even if it's correct,I don't know what is wrong with this code,it should works,but it look like that it can't compair the user answer with "z" wich is the correct answer,I even tried to make it write "z" (that's why there is a "print(z)" on Ln 6) and it still do that even when answer match "z"
I already know that it's possible to make the computer compair a hand-written answer with a variable (like in password programs) but it seems to don't work with random numbers
is it possible to fix it,if yes,how?
thanks