-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path56_quiz.rb
39 lines (34 loc) · 934 Bytes
/
56_quiz.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
file_path = File.dirname(__FILE__)
if File.exist?(file_path + "/modules/data/56_questions.txt") &&
File.exist?(file_path + "/modules/data/56_answers.txt")
questions = File.readlines(file_path + "/modules/data/56_questions.txt")
answers = File.readlines(file_path + "/modules/data/56_answers.txt")
question = 0
answer = nil
correct = 0
incorrect = 0
while question < questions.size
puts questions[question]
unless !answer.nil?
puts "Your answer: "
answer = STDIN.gets.chomp
end
if answer.to_i == answers[question].to_i
puts "Correct!"
correct += 1
else
puts "Incorrect!"
incorrect += 1
puts "User: "
p answer.to_i
puts "Data: "
p answers[question].to_i
end
answer = nil
question += 1
end
puts "\n\n"
puts "Your result:\nCorrect answers: #{correct}\nIncorrect answers: #{incorrect}"
else
puts "Files not found"
end