Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Math Program test
- function genRandomNum() --# Random Function
- num1 = math.random(10)
- num2 = math.random(10)
- sign = math.random(4)
- print("Question: "..questionOn) --# Prints current question the user is on
- if sign == 1 then --# Loop for getting random sign
- answer = num1 + num2
- print("Whats "..num1.." + "..num2.." ?")
- elseif sign == 2 then
- answer = num1 - num2
- print("Whats "..num1.." - "..num2.." ?")
- elseif sign == 3 then
- answer = num1 / num2
- print("Whats "..num1.." / "..num2.." ?")
- elseif sign == 4 then
- answer = num1 * num2
- print("Whats "..num1.." * "..num2.." ?")
- end
- end
- r = 0
- w = 0
- write("How many question do you want to be asked? ")
- numQuestion = tonumber(io.read()) --# Reads how many questions the user wants
- term.clear()
- for x = 1, numQuestion do --# Loops until reaches the users amount of questions
- questionOn = x
- term.clear()
- term.setCursorPos(1,1)
- genRandomNum()
- term.setCursorPos(1, 3)
- write("Answer: ")
- userAnswer = tonumber(io.read())
- if userAnswer == answer then
- r = r + 1 --# Adds to questions correct
- else
- w = w + 1 --# Adds to questions incorrect
- end
- end
- --[[ Prints final results when program has finished ]]--
- term.clear()
- term.setCursorPos(1,1)
- print("Total Questions: "..numQuestion)
- print("You got "..r.." Correct!")
- print("You got "..w.." Wrong. ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement