--Program made by David Gomes
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
counter = 0
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")
print (counter)
break
elseif tried_number > random_number then
print ("Try a lower number")
counter = counter + 1
else
print ("Try a higher number")
counter = counter + 1
end
else
print ("Not a number!")
end
end
else
print("Not a number!")
end
I actually thought that in a WFRNG, when counter=29, then it's right.
Here's a Lua program that is a number guesser, you win when you try the last option.
Example:
Max Value = 5
0
No
1
No
2
No
4
No
5
No
3
Yes
Code:
--Program made by David Gomes
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
counter = 0
while true do
print ("Guess a number: ")
tried_number = io.read("*number")
if type(tried_number) == "number" then
if counter<(max_value) then
print ("Wrong Number")
counter = counter + 1
else
print ("You won")
break
end
else
print ("Not a number!")
end
end
else
print("Not a number!")
end