1246
Computer Programming / Re: Lua Loop Defined By User
« on: May 31, 2011, 05:43:25 pm »
Phew, after a while, I managed to make my first program
I will still add a few checks and other stuff, but this language is not really for me.
EDIT:
Yay, added a few cool stuff:
Code: [Select]
print("Enter number: ")
max_value = io.read("*number") --Get maximum random number
if type(max_value) == "number" then --If the user enters a number
math.randomseed( os.time() )
random_number = math.random(max_value) --Define a number
while true do
print ("Guess a number: ")
tried_number = io.read("*number")
if type(tried_number) == "number" then
if tried_number == random_number then
print ("You Won")
break
end
end
end
else
print("Not a Number!")
end
I will still add a few checks and other stuff, but this language is not really for me.
EDIT:
Yay, added a few cool stuff:
Code: [Select]
print("Enter number: ")
max_value = io.read("*number") --Get maximum random number
if type(max_value) == "number" then --If the user enters a number
math.randomseed( os.time() )
random_number = math.random(max_value) --Define a number
while true do
print ("Guess a number: ")
tried_number = io.read("*number")
if type(tried_number) == "number" then
if tried_number == random_number then
print ("You Won")
break
elseif tried_number > random_number then
print ("Try a lower number")
else
print ("Try a higher number")
end
else
print ("Not a number!")
end
end
else
print("Not a number!")
end