I want to create a simple Quiz program:
1- Display multiple-choice questions one by one (just three in my simple
case)
2- Answer each question with your choice letter
3- Display the number of successful answers
4- Display a good-bye message before exiting the program
Unfortunately, my program doesn’t get off the ground – I get the
following error:
/Users/marcc/.rvm/rubies/ruby-2.1.0/bin/ruby -e
$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)
/Users/marcc/RubymineProjects/Tests/quiz.rb
/Users/marcc/RubymineProjects/Tests/quiz.rb:7:in display_question': wrong number of arguments (6 for 4) (ArgumentError) from /Users/marcc/RubymineProjects/Tests/quiz.rb:35:in
<top
(required)>’
from -e:1:in load' from -e:1:in
’
In the above, what does "wrong number of arguments (6 for 4) mean?
Here is my program:
class Quiz
def initialize(correct_answers)
@correct_answers = correct_answers
end
def display_question( q1, q2, q3, answer)
loop do
puts q1
puts q2
puts q3
print “\nType a letter a, b, c, or d for your answer:”
reply = gets
if answer == reply then
@correct_answers += 1
end
end
end
def quiz_result
print ‘You correctly answered ’ + @correct_answers.to_s + ’
question(s).’
end
def end_game
puts “\t\tThanks for playing, see you next time!.”
end
end
my_quiz = Quiz.new(@correct_answers)
@correct_answers = 0
q1
puts ‘’
my_quiz.display_question(“How many places are called Paris in the
US?”,
“a. 17”, “b. 6”, “c. 25”, “d. 12”, “a”)
q2
puts ‘’
my_quiz.display_question(“What is Uzbekistan’s capital city?”,
“a. Qarshi”, “b. Tashkent”, “c. Bukhara”, “d.
Nukus”, “b”)
q3
puts ‘’
my_quiz.display_question(“What is the most spoken language in Afica?”,
“a. Swahili”, “b. French”, “c. Arabic”, “d.
English”, “d”)
display result
puts ‘’
my_quiz.quiz_result
display end game message
puts ‘’
my_quiz.end_game