Simple Quiz Game

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 `<main>'

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

Check the line 7 and line 35, 38, 41. You will find the answer. The method only have 4 parameter.

···

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

···

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The method
only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

here is my take on what you are trying to do: (I am a learner too)

#!/usr/bin/env ruby

class Q

    attr_reader :correct_answer

    def initialize(q, choices, correct_answer)

        @question = q

        @choices = choices

        @correct_answer = correct_answer

    end

    def display

        puts @question

        a = Array('a'...'z')

        i = 0

        @choices.each { |c|

            puts " #{a[i]}. #{c}"

            i += 1

        }

    end

end

class Quiz

    attr_reader :number_correct

    def initialize

        @q = Array.new

        @number_correct = 0

    end

    def addquestion(q, choices, a)

        question = Q.new(q, choices, a)

        @q << question

    end

    def take_quiz

        @q.each { |qq|

            qq.display

            print "\nanswer? "

            a = gets

            a = a.chomp

            @number_correct += 1 if a == qq.correct_answer

            puts ""

        }

    end

end

quiz = Quiz.new

quiz.addquestion("question #1", ['choice 1.1', 'choice 1.2', 'choice 1.3'],
'a')

quiz.addquestion("question #2", ['choice 2.1', 'choice 2.2', 'choice 2.3'],
'c')

quiz.take_quiz

puts quiz.number_correct

···

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Sun, Dec 13, 2015 at 7:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The method
only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

When you call a method, the arguments you pass into it become local variables within the method. Typically this means you have to pass the same number of arguments into the method as it asks for.

When you write:
     my_quiz.display_question("How many places are called Paris in the US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
     q1 = "How many places are called Paris in the US?"
     q2 = "a. 17"
     q3 = "b. 6"
     answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If you want to display the question, and always have a choice of 4 answers, then one way to go would be:

def display_question(question, a, b, c, d, answer)
     puts question
     puts a
     puts b
     puts c
     puts d
     ...

-Kevin

···

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to understand is the relationship between what I include in my questions (6 arguments) and the arguments that are related to my method (4 arguments: 3 questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com > <mailto:zhenpingfeng@gmail.com>> wrote:

    Check the line 7 and line 35, 38, 41. You will find the answer.
    The method only have 4 parameter.

    在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:

    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 `<main>'

    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

A starting point could be to look into variable-length argument lists or
passing a hash to #display_question

···

On Sun, Dec 13, 2015 at 11:46 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> > wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you
defined 4, and called it with 6.

···

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If you
want to display the question, and always have a choice of 4 answers, then
one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> > wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau < <marc.chanliau@gmail.com>
marc.chanliau@gmail.com> 写道:

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 `<main>'

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

Kevin, that helps. At least the question gets displayed and the user can
type his answer. However, after entering the answer to the first question,
the same question gets displayed again. In other words, I'm not iterating
through the questions. That was the purpose of my exercise: Iterate through
questions, gather responses, and display result.

···

On Sun, Dec 13, 2015 at 9:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If you
want to display the question, and always have a choice of 4 answers, then
one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> > wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau < <marc.chanliau@gmail.com>
marc.chanliau@gmail.com> 写道:

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 `<main>'

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

Jerry, done that. I do get the first question, but I'm not iterating
through the other questions in my loop.

···

On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> wrote:

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the US?", "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you defined 4, and called it with 6.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If
you want to display the question, and always have a choice of 4 answers,
then one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> >> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau < <marc.chanliau@gmail.com>
marc.chanliau@gmail.com> 写道:

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 `<main>'

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

Hey Marc can you paste your new code after you edited it.

mendel

···

On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:

Jerry, done that. I do get the first question, but I'm not iterating
through the other questions in my loop.

On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> wrote:

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the US?", "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you defined 4, and called it with 6.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If
you want to display the question, and always have a choice of 4 answers,
then one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> >>> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau < <marc.chanliau@gmail.com>
marc.chanliau@gmail.com> 写道:

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 `<main>'

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

This is what I have for now. It needs a lot of work! Bottom line is I want
to know how Ruby allows one to "buffer" user responses to questions until
later for displaying results.
Here goes:

class Quiz

  def initialize(correct_answers)
    @correct_answers = correct_answers
  end

  def display_question( question, a, b, c, d, answer)
    loop do
      puts question
      puts a
      puts b
      puts c
      puts d
      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

···

On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson <mmschneerson@gmail.com> wrote:

Hey Marc can you paste your new code after you edited it.

mendel

On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau <marc.chanliau@gmail.com> > wrote:

Jerry, done that. I do get the first question, but I'm not iterating
through the other questions in my loop.

On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> wrote:

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the US?", "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you defined 4, and called it with 6.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If
you want to display the question, and always have a choice of 4 answers,
then one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> >>>> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau < <marc.chanliau@gmail.com>
marc.chanliau@gmail.com> 写道:

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 `<main>'

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

The problem is that you are looping inside the display_question
method, which, I guess, is supposed to handle just one question. You
need to remove the loop.

Jesus.

···

On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:

This is what I have for now. It needs a lot of work! Bottom line is I want
to know how Ruby allows one to "buffer" user responses to questions until
later for displaying results.
Here goes:

class Quiz

  def initialize(correct_answers)
    @correct_answers = correct_answers
  end

  def display_question( question, a, b, c, d, answer)
    loop do
      puts question
      puts a
      puts b
      puts c
      puts d
      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

On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson <mmschneerson@gmail.com> > wrote:

Hey Marc can you paste your new code after you edited it.

mendel

On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau <marc.chanliau@gmail.com> >> wrote:

Jerry, done that. I do get the first question, but I'm not iterating
through the other questions in my loop.

On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> wrote:

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the US?",
"a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you
defined 4, and called it with 6.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

If you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime.
- Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
    my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
    q1 = "How many places are called Paris in the US?"
    q2 = "a. 17"
    q3 = "b. 6"
    answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If
you want to display the question, and always have a choice of 4 answers,
then one way to go would be:

def display_question(question, a, b, c, d, answer)
    puts question
    puts a
    puts b
    puts c
    puts d
    ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> >>>>> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

You know it's legit when Jesus answers your question

···

Sent from my iPhone

On Dec 15, 2015, at 2:41 AM, Jesús Gabriel y Galán <jgabrielygalan@gmail.com> wrote:

The problem is that you are looping inside the display_question
method, which, I guess, is supposed to handle just one question. You
need to remove the loop.

Jesus.

On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:
This is what I have for now. It needs a lot of work! Bottom line is I want
to know how Ruby allows one to "buffer" user responses to questions until
later for displaying results.
Here goes:

class Quiz

def initialize(correct_answers)
   @correct_answers = correct_answers
end

def display_question( question, a, b, c, d, answer)
   loop do
     puts question
     puts a
     puts b
     puts c
     puts d
     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

On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson <mmschneerson@gmail.com> >> wrote:

Hey Marc can you paste your new code after you edited it.

mendel

On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau <marc.chanliau@gmail.com> >>> wrote:

Jerry, done that. I do get the first question, but I'm not iterating
through the other questions in my loop.

On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> wrote:

to put it as simply as I can:

def display_question( q1, q2, q3, answer) has 4 arguments

when you call it:

my_quiz.display_question("How many places are called Paris in the US?",
"a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments

you must call it with the same number of arguments as you defined. you
defined 4, and called it with 6.

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

If you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime.
- Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson

On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:

When you call a method, the arguments you pass into it become local
variables within the method. Typically this means you have to pass the same
number of arguments into the method as it asks for.

When you write:
   my_quiz.display_question("How many places are called Paris in the
US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")

the method display_question sets:
   q1 = "How many places are called Paris in the US?"
   q2 = "a. 17"
   q3 = "b. 6"
   answer = "c. 25"

but it has no idea what to do with "d. 12" or "a". Hence the error. If
you want to display the question, and always have a choice of 4 answers,
then one way to go would be:

def display_question(question, a, b, c, d, answer)
   puts question
   puts a
   puts b
   puts c
   puts d
   ...

-Kevin

On 12/13/2015 10:46 PM, Marc Chanliau wrote:

Understood. I had noticed that before. However, what I don't seem to
understand is the relationship between what I include in my questions (6
arguments) and the arguments that are related to my method (4 arguments: 3
questions and the answer for each).

On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing <zhenpingfeng@gmail.com> >>>>>> wrote:

Check the line 7 and line 35, 38, 41. You will find the answer. The
method only have 4 parameter.

在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:

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 `<main>'

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

Jesus, thanks. I realize that I'm looping on one question only. I want to
loop over all the questions but the challenge is that I want to collect the
data (whether the user provided the right answers or not) to display the
result at the end. The key here is the "collect the data" part that I'm
struggling with.

···

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:

The problem is that you are looping inside the display_question
method, which, I guess, is supposed to handle just one question. You
need to remove the loop.

Jesus.

On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau <marc.chanliau@gmail.com> > wrote:
> This is what I have for now. It needs a lot of work! Bottom line is I
want
> to know how Ruby allows one to "buffer" user responses to questions until
> later for displaying results.
> Here goes:
>
> class Quiz
>
> def initialize(correct_answers)
> @correct_answers = correct_answers
> end
>
> def display_question( question, a, b, c, d, answer)
> loop do
> puts question
> puts a
> puts b
> puts c
> puts d
> 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
>
>
> On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson < > mmschneerson@gmail.com> > > wrote:
>>
>> Hey Marc can you paste your new code after you edited it.
>>
>> mendel
>>
>> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau <marc.chanliau@gmail.com > > > >> wrote:
>>>
>>> Jerry, done that. I do get the first question, but I'm not iterating
>>> through the other questions in my loop.
>>>
>>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com> > wrote:
>>>>
>>>> to put it as simply as I can:
>>>>
>>>> def display_question( q1, q2, q3, answer) has 4 arguments
>>>>
>>>> when you call it:
>>>>
>>>> my_quiz.display_question("How many places are called Paris in the
US?",
>>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
>>>>
>>>> you must call it with the same number of arguments as you defined. you
>>>> defined 4, and called it with 6.
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Extra Ham Operator: K7AZJ
>>>> Registered Linux User: 275424
>>>> Raspberry Pi and Arduino developer
>>>>
>>>> The most exciting phrase to hear in science - the one that heralds new
>>>> discoveries - is not "Eureka!" but "That's funny...".
>>>> - Isaac. Asimov
>>>>
>>>> If you give someone a program, you will frustrate them for a day; if
you
>>>> teach them how to program, you will frustrate them for a lifetime.
>>>> - Anonymous
>>>>
>>>> If writing good code requires very little comments, then writing
really
>>>> excellent code requires no comments at all!
>>>> - Ken Thompson
>>>>
>>>>
>>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com> wrote:
>>>>>
>>>>> When you call a method, the arguments you pass into it become local
>>>>> variables within the method. Typically this means you have to pass
the same
>>>>> number of arguments into the method as it asks for.
>>>>>
>>>>> When you write:
>>>>> my_quiz.display_question("How many places are called Paris in the
>>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
>>>>>
>>>>> the method display_question sets:
>>>>> q1 = "How many places are called Paris in the US?"
>>>>> q2 = "a. 17"
>>>>> q3 = "b. 6"
>>>>> answer = "c. 25"
>>>>>
>>>>> but it has no idea what to do with "d. 12" or "a". Hence the error.
If
>>>>> you want to display the question, and always have a choice of 4
answers,
>>>>> then one way to go would be:
>>>>>
>>>>> def display_question(question, a, b, c, d, answer)
>>>>> puts question
>>>>> puts a
>>>>> puts b
>>>>> puts c
>>>>> puts d
>>>>> ...
>>>>>
>>>>> -Kevin
>>>>>
>>>>>
>>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
>>>>>
>>>>> Understood. I had noticed that before. However, what I don't seem to
>>>>> understand is the relationship between what I include in my
questions (6
>>>>> arguments) and the arguments that are related to my method (4
arguments: 3
>>>>> questions and the answer for each).
>>>>>
>>>>>
>>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing < > zhenpingfeng@gmail.com> > >>>>> wrote:
>>>>>>
>>>>>> Check the line 7 and line 35, 38, 41. You will find the answer. The
>>>>>> method only have 4 parameter.
>>>>>>
>>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau <marc.chanliau@gmail.com> 写道:
>>>>>>
>>>>>> 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 `<main>'
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Marc, you need to set up a place to store the answers and/or correct/wrong, and store the result BEFORE exiting you quesrion loop.

···

On 15/12/2015 6:48 PM, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want to loop over all the questions but the challenge is that I want to collect the data (whether the user provided the right answers or not) to display the result at the end. The key here is the "collect the data" part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán > <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau > <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
    > This is what I have for now. It needs a lot of work! Bottom line
    is I want
    > to know how Ruby allows one to "buffer" user responses to
    questions until
    > later for displaying results.
    > Here goes:
    >
    > class Quiz
    >
    > def initialize(correct_answers)
    > @correct_answers = correct_answers
    > end
    >
    > def display_question( question, a, b, c, d, answer)
    > loop do
    > puts question
    > puts a
    > puts b
    > puts c
    > puts d
    > 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
    >
    > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson > <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> > > wrote:
    >>
    >> Hey Marc can you paste your new code after you edited it.
    >>
    >> mendel
    >>
    >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau > <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> > >> wrote:
    >>>
    >>> Jerry, done that. I do get the first question, but I'm not
    iterating
    >>> through the other questions in my loop.
    >>>
    >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis > <jdawgaz@gmail.com <mailto:jdawgaz@gmail.com>> wrote:
    >>>>
    >>>> to put it as simply as I can:
    >>>>
    >>>> def display_question( q1, q2, q3, answer) has 4 arguments
    >>>>
    >>>> when you call it:
    >>>>
    >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
    >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
    >>>>
    >>>> you must call it with the same number of arguments as you
    defined. you
    >>>> defined 4, and called it with 6.
    >>>>
    >>>> --
    >>>> Extra Ham Operator: K7AZJ
    >>>> Registered Linux User: 275424
    >>>> Raspberry Pi and Arduino developer
    >>>>
    >>>> The most exciting phrase to hear in science - the one that
    heralds new
    >>>> discoveries - is not "Eureka!" but "That's funny...".
    >>>> - Isaac. Asimov
    >>>>
    >>>> If you give someone a program, you will frustrate them for a
    day; if you
    >>>> teach them how to program, you will frustrate them for a
    lifetime.
    >>>> - Anonymous
    >>>>
    >>>> If writing good code requires very little comments, then
    writing really
    >>>> excellent code requires no comments at all!
    >>>> - Ken Thompson
    >>>>
    >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com > <mailto:kcclaas@gmail.com>> wrote:
    >>>>>
    >>>>> When you call a method, the arguments you pass into it
    become local
    >>>>> variables within the method. Typically this means you have
    to pass the same
    >>>>> number of arguments into the method as it asks for.
    >>>>>
    >>>>> When you write:
    >>>>> my_quiz.display_question("How many places are called
    Paris in the
    >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
    >>>>>
    >>>>> the method display_question sets:
    >>>>> q1 = "How many places are called Paris in the US?"
    >>>>> q2 = "a. 17"
    >>>>> q3 = "b. 6"
    >>>>> answer = "c. 25"
    >>>>>
    >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
    >>>>> you want to display the question, and always have a choice
    of 4 answers,
    >>>>> then one way to go would be:
    >>>>>
    >>>>> def display_question(question, a, b, c, d, answer)
    >>>>> puts question
    >>>>> puts a
    >>>>> puts b
    >>>>> puts c
    >>>>> puts d
    >>>>> ...
    >>>>>
    >>>>> -Kevin
    >>>>>
    >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
    >>>>>
    >>>>> Understood. I had noticed that before. However, what I don't
    seem to
    >>>>> understand is the relationship between what I include in my
    questions (6
    >>>>> arguments) and the arguments that are related to my method
    (4 arguments: 3
    >>>>> questions and the answer for each).
    >>>>>
    >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing > <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> > >>>>> wrote:
    >>>>>>
    >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
    >>>>>> method only have 4 parameter.
    >>>>>>
    >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:
    >>>>>>
    >>>>>> 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 `<main>'
    >>>>>>
    >>>>>> 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
    >>>>>>
    >>>>>
    >>>>
    >>>
    >>
    >

No virus found in this message.
Checked by AVG - www.avg.com <http://www.avg.com>
Version: 2016.0.7294 / Virus Database: 4489/11185 - Release Date: 12/15/15

--
Patrick Bayford Tel : 020 8265 8376 E-mail : pbayford@talktalk.net

A user interface is usually such a pain in the arse to write that it's a good idea to split it off into a module, or at least a class or two.

A good place to start with a problem like this is to think about what classes you need. While there are different ways of skinning this cat, you might for example have:

Questions: A question is associated to a correct answer.

Answers/Responses: An answer/response is a potential answer to a question

Rounds: A round consists of a question and n answers/responses (one of the answers has to be correct) and return true or false depending on the response entered.

Score: Number of rounds correctly answered.

The UI has to print rounds, get user response and print the score. Don't worry about having classes that don't seem to do much especially because the ruby library seems so powerful.

(Anyway, then you probably want to read in the questions and answers from a text file.)

···

On 15.12.2015 19:48, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want
to loop over all the questions but the challenge is that I want to
collect the data (whether the user provided the right answers or not) to
display the result at the end. The key here is the "collect the data"
part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán > <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau > <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
     > This is what I have for now. It needs a lot of work! Bottom line
    is I want
     > to know how Ruby allows one to "buffer" user responses to
    questions until
     > later for displaying results.
     > Here goes:
     >
     > class Quiz
     >
     > def initialize(correct_answers)
     > @correct_answers = correct_answers
     > end
     >
     > def display_question( question, a, b, c, d, answer)
     > loop do
     > puts question
     > puts a
     > puts b
     > puts c
     > puts d
     > 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
     >
     > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson > <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> > > wrote:
     >>
     >> Hey Marc can you paste your new code after you edited it.
     >>
     >> mendel
     >>
     >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau > <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> > >> wrote:
     >>>
     >>> Jerry, done that. I do get the first question, but I'm not
    iterating
     >>> through the other questions in my loop.
     >>>
     >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com > <mailto:jdawgaz@gmail.com>> wrote:
     >>>>
     >>>> to put it as simply as I can:
     >>>>
     >>>> def display_question( q1, q2, q3, answer) has 4 arguments
     >>>>
     >>>> when you call it:
     >>>>
     >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
     >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
     >>>>
     >>>> you must call it with the same number of arguments as you
    defined. you
     >>>> defined 4, and called it with 6.
     >>>>
     >>>> --
     >>>> Extra Ham Operator: K7AZJ
     >>>> Registered Linux User: 275424
     >>>> Raspberry Pi and Arduino developer
     >>>>
     >>>> The most exciting phrase to hear in science - the one that
    heralds new
     >>>> discoveries - is not "Eureka!" but "That's funny...".
     >>>> - Isaac. Asimov
     >>>>
     >>>> If you give someone a program, you will frustrate them for a
    day; if you
     >>>> teach them how to program, you will frustrate them for a lifetime.
     >>>> - Anonymous
     >>>>
     >>>> If writing good code requires very little comments, then
    writing really
     >>>> excellent code requires no comments at all!
     >>>> - Ken Thompson
     >>>>
     >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com > <mailto:kcclaas@gmail.com>> wrote:
     >>>>>
     >>>>> When you call a method, the arguments you pass into it become
    local
     >>>>> variables within the method. Typically this means you have to
    pass the same
     >>>>> number of arguments into the method as it asks for.
     >>>>>
     >>>>> When you write:
     >>>>> my_quiz.display_question("How many places are called
    Paris in the
     >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
     >>>>>
     >>>>> the method display_question sets:
     >>>>> q1 = "How many places are called Paris in the US?"
     >>>>> q2 = "a. 17"
     >>>>> q3 = "b. 6"
     >>>>> answer = "c. 25"
     >>>>>
     >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
     >>>>> you want to display the question, and always have a choice of
    4 answers,
     >>>>> then one way to go would be:
     >>>>>
     >>>>> def display_question(question, a, b, c, d, answer)
     >>>>> puts question
     >>>>> puts a
     >>>>> puts b
     >>>>> puts c
     >>>>> puts d
     >>>>> ...
     >>>>>
     >>>>> -Kevin
     >>>>>
     >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
     >>>>>
     >>>>> Understood. I had noticed that before. However, what I don't
    seem to
     >>>>> understand is the relationship between what I include in my
    questions (6
     >>>>> arguments) and the arguments that are related to my method (4
    arguments: 3
     >>>>> questions and the answer for each).
     >>>>>
     >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing > <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> > >>>>> wrote:
     >>>>>>
     >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
     >>>>>> method only have 4 parameter.
     >>>>>>
     >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:
     >>>>>>
     >>>>>> 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 `<main>'
     >>>>>>
     >>>>>> 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
     >>>>>>
     >>>>>
     >>>>
     >>>
     >>
     >

Thanks, Joe. Yes, ultimately, I will try to have the questions in a
separate text file, but I'm not there yet! The idea of having several
classes sounds interesting. I'll look into it.

···

On Tue, Dec 15, 2015 at 1:04 PM, Joe Gain <joe.gain@gmail.com> wrote:

On 15.12.2015 19:48, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want
to loop over all the questions but the challenge is that I want to
collect the data (whether the user provided the right answers or not) to
display the result at the end. The key here is the "collect the data"
part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán >> <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau >> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
     > This is what I have for now. It needs a lot of work! Bottom line
    is I want
     > to know how Ruby allows one to "buffer" user responses to
    questions until
     > later for displaying results.
     > Here goes:
     >
     > class Quiz
     >
     > def initialize(correct_answers)
     > @correct_answers = correct_answers
     > end
     >
     > def display_question( question, a, b, c, d, answer)
     > loop do
     > puts question
     > puts a
     > puts b
     > puts c
     > puts d
     > 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
     >
     >
     > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson >> <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> >> > wrote:
     >>
     >> Hey Marc can you paste your new code after you edited it.
     >>
     >> mendel
     >>
     >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau >> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> >> >> wrote:
     >>>
     >>> Jerry, done that. I do get the first question, but I'm not
    iterating
     >>> through the other questions in my loop.
     >>>
     >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com >> <mailto:jdawgaz@gmail.com>> wrote:
     >>>>
     >>>> to put it as simply as I can:
     >>>>
     >>>> def display_question( q1, q2, q3, answer) has 4 arguments
     >>>>
     >>>> when you call it:
     >>>>
     >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
     >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
     >>>>
     >>>> you must call it with the same number of arguments as you
    defined. you
     >>>> defined 4, and called it with 6.
     >>>>
     >>>>
     >>>>
     >>>>
     >>>> --
     >>>> Extra Ham Operator: K7AZJ
     >>>> Registered Linux User: 275424
     >>>> Raspberry Pi and Arduino developer
     >>>>
     >>>> The most exciting phrase to hear in science - the one that
    heralds new
     >>>> discoveries - is not "Eureka!" but "That's funny...".
     >>>> - Isaac. Asimov
     >>>>
     >>>> If you give someone a program, you will frustrate them for a
    day; if you
     >>>> teach them how to program, you will frustrate them for a
lifetime.
     >>>> - Anonymous
     >>>>
     >>>> If writing good code requires very little comments, then
    writing really
     >>>> excellent code requires no comments at all!
     >>>> - Ken Thompson
     >>>>
     >>>>
     >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com >> <mailto:kcclaas@gmail.com>> wrote:
     >>>>>
     >>>>> When you call a method, the arguments you pass into it become
    local
     >>>>> variables within the method. Typically this means you have to
    pass the same
     >>>>> number of arguments into the method as it asks for.
     >>>>>
     >>>>> When you write:
     >>>>> my_quiz.display_question("How many places are called
    Paris in the
     >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
     >>>>>
     >>>>> the method display_question sets:
     >>>>> q1 = "How many places are called Paris in the US?"
     >>>>> q2 = "a. 17"
     >>>>> q3 = "b. 6"
     >>>>> answer = "c. 25"
     >>>>>
     >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
     >>>>> you want to display the question, and always have a choice of
    4 answers,
     >>>>> then one way to go would be:
     >>>>>
     >>>>> def display_question(question, a, b, c, d, answer)
     >>>>> puts question
     >>>>> puts a
     >>>>> puts b
     >>>>> puts c
     >>>>> puts d
     >>>>> ...
     >>>>>
     >>>>> -Kevin
     >>>>>
     >>>>>
     >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
     >>>>>
     >>>>> Understood. I had noticed that before. However, what I don't
    seem to
     >>>>> understand is the relationship between what I include in my
    questions (6
     >>>>> arguments) and the arguments that are related to my method (4
    arguments: 3
     >>>>> questions and the answer for each).
     >>>>>
     >>>>>
     >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing >> <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> >> >>>>> wrote:
     >>>>>>
     >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
     >>>>>> method only have 4 parameter.
     >>>>>>
     >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:

     >>>>>>
     >>>>>> 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 `<main>'
     >>>>>>
     >>>>>> 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
     >>>>>>
     >>>>>>
     >>>>>>
     >>>>>
     >>>>>
     >>>>
     >>>
     >>
     >

A user interface is usually such a pain in the arse to write that it's a
good idea to split it off into a module, or at least a class or two.

A good place to start with a problem like this is to think about what
classes you need. While there are different ways of skinning this cat, you
might for example have:

Questions: A question is associated to a correct answer.

Answers/Responses: An answer/response is a potential answer to a question

Rounds: A round consists of a question and n answers/responses (one of the
answers has to be correct) and return true or false depending on the
response entered.

Score: Number of rounds correctly answered.

The UI has to print rounds, get user response and print the score. Don't
worry about having classes that don't seem to do much especially because
the ruby library seems so powerful.

(Anyway, then you probably want to read in the questions and answers from
a text file.)

marc,

look back to my response, and study it.
I believe you will find what you are looking for.

jerry

···

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Tue, Dec 15, 2015 at 2:55 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:

Thanks, Joe. Yes, ultimately, I will try to have the questions in a
separate text file, but I'm not there yet! The idea of having several
classes sounds interesting. I'll look into it.

On Tue, Dec 15, 2015 at 1:04 PM, Joe Gain <joe.gain@gmail.com> wrote:

On 15.12.2015 19:48, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want
to loop over all the questions but the challenge is that I want to
collect the data (whether the user provided the right answers or not) to
display the result at the end. The key here is the "collect the data"
part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán >>> <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau >>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
     > This is what I have for now. It needs a lot of work! Bottom line
    is I want
     > to know how Ruby allows one to "buffer" user responses to
    questions until
     > later for displaying results.
     > Here goes:
     >
     > class Quiz
     >
     > def initialize(correct_answers)
     > @correct_answers = correct_answers
     > end
     >
     > def display_question( question, a, b, c, d, answer)
     > loop do
     > puts question
     > puts a
     > puts b
     > puts c
     > puts d
     > 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
     >
     >
     > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson >>> <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> >>> > wrote:
     >>
     >> Hey Marc can you paste your new code after you edited it.
     >>
     >> mendel
     >>
     >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau >>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> >>> >> wrote:
     >>>
     >>> Jerry, done that. I do get the first question, but I'm not
    iterating
     >>> through the other questions in my loop.
     >>>
     >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis <jdawgaz@gmail.com >>> <mailto:jdawgaz@gmail.com>> wrote:
     >>>>
     >>>> to put it as simply as I can:
     >>>>
     >>>> def display_question( q1, q2, q3, answer) has 4 arguments
     >>>>
     >>>> when you call it:
     >>>>
     >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
     >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
     >>>>
     >>>> you must call it with the same number of arguments as you
    defined. you
     >>>> defined 4, and called it with 6.
     >>>>
     >>>>
     >>>>
     >>>>
     >>>> --
     >>>> Extra Ham Operator: K7AZJ
     >>>> Registered Linux User: 275424
     >>>> Raspberry Pi and Arduino developer
     >>>>
     >>>> The most exciting phrase to hear in science - the one that
    heralds new
     >>>> discoveries - is not "Eureka!" but "That's funny...".
     >>>> - Isaac. Asimov
     >>>>
     >>>> If you give someone a program, you will frustrate them for a
    day; if you
     >>>> teach them how to program, you will frustrate them for a
lifetime.
     >>>> - Anonymous
     >>>>
     >>>> If writing good code requires very little comments, then
    writing really
     >>>> excellent code requires no comments at all!
     >>>> - Ken Thompson
     >>>>
     >>>>
     >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com >>> <mailto:kcclaas@gmail.com>> wrote:
     >>>>>
     >>>>> When you call a method, the arguments you pass into it become
    local
     >>>>> variables within the method. Typically this means you have to
    pass the same
     >>>>> number of arguments into the method as it asks for.
     >>>>>
     >>>>> When you write:
     >>>>> my_quiz.display_question("How many places are called
    Paris in the
     >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
     >>>>>
     >>>>> the method display_question sets:
     >>>>> q1 = "How many places are called Paris in the US?"
     >>>>> q2 = "a. 17"
     >>>>> q3 = "b. 6"
     >>>>> answer = "c. 25"
     >>>>>
     >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
     >>>>> you want to display the question, and always have a choice of
    4 answers,
     >>>>> then one way to go would be:
     >>>>>
     >>>>> def display_question(question, a, b, c, d, answer)
     >>>>> puts question
     >>>>> puts a
     >>>>> puts b
     >>>>> puts c
     >>>>> puts d
     >>>>> ...
     >>>>>
     >>>>> -Kevin
     >>>>>
     >>>>>
     >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
     >>>>>
     >>>>> Understood. I had noticed that before. However, what I don't
    seem to
     >>>>> understand is the relationship between what I include in my
    questions (6
     >>>>> arguments) and the arguments that are related to my method (4
    arguments: 3
     >>>>> questions and the answer for each).
     >>>>>
     >>>>>
     >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing >>> <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> >>> >>>>> wrote:
     >>>>>>
     >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
     >>>>>> method only have 4 parameter.
     >>>>>>
     >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:

     >>>>>>
     >>>>>> 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 `<main>'
     >>>>>>
     >>>>>> 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
     >>>>>>
     >>>>>>
     >>>>>>
     >>>>>
     >>>>>
     >>>>
     >>>
     >>
     >

A user interface is usually such a pain in the arse to write that it's a
good idea to split it off into a module, or at least a class or two.

A good place to start with a problem like this is to think about what
classes you need. While there are different ways of skinning this cat, you
might for example have:

Questions: A question is associated to a correct answer.

Answers/Responses: An answer/response is a potential answer to a question

Rounds: A round consists of a question and n answers/responses (one of
the answers has to be correct) and return true or false depending on the
response entered.

Score: Number of rounds correctly answered.

The UI has to print rounds, get user response and print the score. Don't
worry about having classes that don't seem to do much especially because
the ruby library seems so powerful.

(Anyway, then you probably want to read in the questions and answers from
a text file.)

Jerry, I'm back to that. Trying to figure out the arrays, but it basically
does what I want it to do.

···

On Tue, Dec 15, 2015 at 2:16 PM, Jerry Davis <jdawgaz@gmail.com> wrote:

marc,

look back to my response, and study it.
I believe you will find what you are looking for.

jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Tue, Dec 15, 2015 at 2:55 PM, Marc Chanliau <marc.chanliau@gmail.com> > wrote:

Thanks, Joe. Yes, ultimately, I will try to have the questions in a
separate text file, but I'm not there yet! The idea of having several
classes sounds interesting. I'll look into it.

On Tue, Dec 15, 2015 at 1:04 PM, Joe Gain <joe.gain@gmail.com> wrote:

On 15.12.2015 19:48, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want
to loop over all the questions but the challenge is that I want to
collect the data (whether the user provided the right answers or not) to
display the result at the end. The key here is the "collect the data"
part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán >>>> <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau >>>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
     > This is what I have for now. It needs a lot of work! Bottom line
    is I want
     > to know how Ruby allows one to "buffer" user responses to
    questions until
     > later for displaying results.
     > Here goes:
     >
     > class Quiz
     >
     > def initialize(correct_answers)
     > @correct_answers = correct_answers
     > end
     >
     > def display_question( question, a, b, c, d, answer)
     > loop do
     > puts question
     > puts a
     > puts b
     > puts c
     > puts d
     > 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
     >
     >
     > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson >>>> <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> >>>> > wrote:
     >>
     >> Hey Marc can you paste your new code after you edited it.
     >>
     >> mendel
     >>
     >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau >>>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> >>>> >> wrote:
     >>>
     >>> Jerry, done that. I do get the first question, but I'm not
    iterating
     >>> through the other questions in my loop.
     >>>
     >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis < >>>> jdawgaz@gmail.com >>>> <mailto:jdawgaz@gmail.com>> wrote:
     >>>>
     >>>> to put it as simply as I can:
     >>>>
     >>>> def display_question( q1, q2, q3, answer) has 4 arguments
     >>>>
     >>>> when you call it:
     >>>>
     >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
     >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
     >>>>
     >>>> you must call it with the same number of arguments as you
    defined. you
     >>>> defined 4, and called it with 6.
     >>>>
     >>>>
     >>>>
     >>>>
     >>>> --
     >>>> Extra Ham Operator: K7AZJ
     >>>> Registered Linux User: 275424
     >>>> Raspberry Pi and Arduino developer
     >>>>
     >>>> The most exciting phrase to hear in science - the one that
    heralds new
     >>>> discoveries - is not "Eureka!" but "That's funny...".
     >>>> - Isaac. Asimov
     >>>>
     >>>> If you give someone a program, you will frustrate them for a
    day; if you
     >>>> teach them how to program, you will frustrate them for a
lifetime.
     >>>> - Anonymous
     >>>>
     >>>> If writing good code requires very little comments, then
    writing really
     >>>> excellent code requires no comments at all!
     >>>> - Ken Thompson
     >>>>
     >>>>
     >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com >>>> <mailto:kcclaas@gmail.com>> wrote:
     >>>>>
     >>>>> When you call a method, the arguments you pass into it become
    local
     >>>>> variables within the method. Typically this means you have to
    pass the same
     >>>>> number of arguments into the method as it asks for.
     >>>>>
     >>>>> When you write:
     >>>>> my_quiz.display_question("How many places are called
    Paris in the
     >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
     >>>>>
     >>>>> the method display_question sets:
     >>>>> q1 = "How many places are called Paris in the US?"
     >>>>> q2 = "a. 17"
     >>>>> q3 = "b. 6"
     >>>>> answer = "c. 25"
     >>>>>
     >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
     >>>>> you want to display the question, and always have a choice of
    4 answers,
     >>>>> then one way to go would be:
     >>>>>
     >>>>> def display_question(question, a, b, c, d, answer)
     >>>>> puts question
     >>>>> puts a
     >>>>> puts b
     >>>>> puts c
     >>>>> puts d
     >>>>> ...
     >>>>>
     >>>>> -Kevin
     >>>>>
     >>>>>
     >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
     >>>>>
     >>>>> Understood. I had noticed that before. However, what I don't
    seem to
     >>>>> understand is the relationship between what I include in my
    questions (6
     >>>>> arguments) and the arguments that are related to my method (4
    arguments: 3
     >>>>> questions and the answer for each).
     >>>>>
     >>>>>
     >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing >>>> <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> >>>> >>>>> wrote:
     >>>>>>
     >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
     >>>>>> method only have 4 parameter.
     >>>>>>
     >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:

     >>>>>>
     >>>>>> 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 `<main>'
     >>>>>>
     >>>>>> 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
     >>>>>>
     >>>>>>
     >>>>>>
     >>>>>
     >>>>>
     >>>>
     >>>
     >>
     >

A user interface is usually such a pain in the arse to write that it's a
good idea to split it off into a module, or at least a class or two.

A good place to start with a problem like this is to think about what
classes you need. While there are different ways of skinning this cat, you
might for example have:

Questions: A question is associated to a correct answer.

Answers/Responses: An answer/response is a potential answer to a question

Rounds: A round consists of a question and n answers/responses (one of
the answers has to be correct) and return true or false depending on the
response entered.

Score: Number of rounds correctly answered.

The UI has to print rounds, get user response and print the score. Don't
worry about having classes that don't seem to do much especially because
the ruby library seems so powerful.

(Anyway, then you probably want to read in the questions and answers
from a text file.)

Jerry, I followed your advice. Breaking down the program into several
classes is more manageable. I've changed a few things in your program, most
notably the fact that I print the results from the take_quiz method (seems
more logical to me) and I've modified its format. Here is the program now
(works fine):

class QuestionClass

  attr_reader :correct_answer

  def initialize(question, choices, correct_answer)
    @question = question
    @choices = choices
    @correct_answer = correct_answer
  end

  def display
    puts @question
    a = Array('a'...'z')
    i = 0
    @choices.each { |c|
      puts " #{a[i]}. #{c}"
      i += 1
    }
  end
end

class QuizClass

  attr_reader :nb_of_correct_answers

  def initialize
    @q = Array.new
    @nb_of_correct_answers = 0
  end

  def add_question(q, choices, a)
    question = QuestionClass.new(q, choices, a)
    @q << question
  end

  def take_quiz
    @q.each { |qq|
      qq.display
      print "\nanswer? "
      a = gets
      a = a.chomp
      @nb_of_correct_answers += 1 if a == qq.correct_answer
      puts "You have answered #{@nb_of_correct_answers} questions correctly"
    }
  end
end

quiz = QuizClass.new
quiz.add_question('How many places are called Paris in the US?', [17,
6, 25], 'a')
quiz.add_question("What is Uzbekistan's capital city?", ['Qarshi',
'Tashkent', 'Bukhara'], 'b')
quiz.add_question('What is the most spoken language in Africa?',
['Swahili', 'Arabic', 'English'], 'c')
quiz.take_quiz

Now, I have two things to do:
(1) Handle incorrect user input
(2) Feed the questions from a separate text file

Thanks for the help. I got me out of the rut.

···

On Tue, Dec 15, 2015 at 2:16 PM, Jerry Davis <jdawgaz@gmail.com> wrote:

marc,

look back to my response, and study it.
I believe you will find what you are looking for.

jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

*The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov

*I*
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

*If writing good code requires very little comments, then writing really
excellent code requires no comments at all!*- Ken Thompson

On Tue, Dec 15, 2015 at 2:55 PM, Marc Chanliau <marc.chanliau@gmail.com> > wrote:

Thanks, Joe. Yes, ultimately, I will try to have the questions in a
separate text file, but I'm not there yet! The idea of having several
classes sounds interesting. I'll look into it.

On Tue, Dec 15, 2015 at 1:04 PM, Joe Gain <joe.gain@gmail.com> wrote:

On 15.12.2015 19:48, Marc Chanliau wrote:

Jesus, thanks. I realize that I'm looping on one question only. I want
to loop over all the questions but the challenge is that I want to
collect the data (whether the user provided the right answers or not) to
display the result at the end. The key here is the "collect the data"
part that I'm struggling with.

On Tue, Dec 15, 2015 at 12:41 AM, Jesús Gabriel y Galán >>>> <jgabrielygalan@gmail.com <mailto:jgabrielygalan@gmail.com>> wrote:

    The problem is that you are looping inside the display_question
    method, which, I guess, is supposed to handle just one question. You
    need to remove the loop.

    Jesus.

    On Mon, Dec 14, 2015 at 9:57 PM, Marc Chanliau >>>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> wrote:
     > This is what I have for now. It needs a lot of work! Bottom line
    is I want
     > to know how Ruby allows one to "buffer" user responses to
    questions until
     > later for displaying results.
     > Here goes:
     >
     > class Quiz
     >
     > def initialize(correct_answers)
     > @correct_answers = correct_answers
     > end
     >
     > def display_question( question, a, b, c, d, answer)
     > loop do
     > puts question
     > puts a
     > puts b
     > puts c
     > puts d
     > 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
     >
     >
     > On Mon, Dec 14, 2015 at 12:33 PM, Mendel Schneerson >>>> <mmschneerson@gmail.com <mailto:mmschneerson@gmail.com>> >>>> > wrote:
     >>
     >> Hey Marc can you paste your new code after you edited it.
     >>
     >> mendel
     >>
     >> On Mon, Dec 14, 2015 at 3:03 PM, Marc Chanliau >>>> <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> >>>> >> wrote:
     >>>
     >>> Jerry, done that. I do get the first question, but I'm not
    iterating
     >>> through the other questions in my loop.
     >>>
     >>> On Mon, Dec 14, 2015 at 6:14 AM, Jerry Davis < >>>> jdawgaz@gmail.com >>>> <mailto:jdawgaz@gmail.com>> wrote:
     >>>>
     >>>> to put it as simply as I can:
     >>>>
     >>>> def display_question( q1, q2, q3, answer) has 4 arguments
     >>>>
     >>>> when you call it:
     >>>>
     >>>> my_quiz.display_question("How many places are called Paris in
    the US?",
     >>>> "a. 17", "b. 6", "c. 25", "d. 12", "a") has 6 arguments
     >>>>
     >>>> you must call it with the same number of arguments as you
    defined. you
     >>>> defined 4, and called it with 6.
     >>>>
     >>>>
     >>>>
     >>>>
     >>>> --
     >>>> Extra Ham Operator: K7AZJ
     >>>> Registered Linux User: 275424
     >>>> Raspberry Pi and Arduino developer
     >>>>
     >>>> The most exciting phrase to hear in science - the one that
    heralds new
     >>>> discoveries - is not "Eureka!" but "That's funny...".
     >>>> - Isaac. Asimov
     >>>>
     >>>> If you give someone a program, you will frustrate them for a
    day; if you
     >>>> teach them how to program, you will frustrate them for a
lifetime.
     >>>> - Anonymous
     >>>>
     >>>> If writing good code requires very little comments, then
    writing really
     >>>> excellent code requires no comments at all!
     >>>> - Ken Thompson
     >>>>
     >>>>
     >>>> On Sun, Dec 13, 2015 at 10:09 PM, Kevin <kcclaas@gmail.com >>>> <mailto:kcclaas@gmail.com>> wrote:
     >>>>>
     >>>>> When you call a method, the arguments you pass into it become
    local
     >>>>> variables within the method. Typically this means you have to
    pass the same
     >>>>> number of arguments into the method as it asks for.
     >>>>>
     >>>>> When you write:
     >>>>> my_quiz.display_question("How many places are called
    Paris in the
     >>>>> US?", "a. 17", "b. 6", "c. 25", "d. 12", "a")
     >>>>>
     >>>>> the method display_question sets:
     >>>>> q1 = "How many places are called Paris in the US?"
     >>>>> q2 = "a. 17"
     >>>>> q3 = "b. 6"
     >>>>> answer = "c. 25"
     >>>>>
     >>>>> but it has no idea what to do with "d. 12" or "a". Hence the
    error. If
     >>>>> you want to display the question, and always have a choice of
    4 answers,
     >>>>> then one way to go would be:
     >>>>>
     >>>>> def display_question(question, a, b, c, d, answer)
     >>>>> puts question
     >>>>> puts a
     >>>>> puts b
     >>>>> puts c
     >>>>> puts d
     >>>>> ...
     >>>>>
     >>>>> -Kevin
     >>>>>
     >>>>>
     >>>>> On 12/13/2015 10:46 PM, Marc Chanliau wrote:
     >>>>>
     >>>>> Understood. I had noticed that before. However, what I don't
    seem to
     >>>>> understand is the relationship between what I include in my
    questions (6
     >>>>> arguments) and the arguments that are related to my method (4
    arguments: 3
     >>>>> questions and the answer for each).
     >>>>>
     >>>>>
     >>>>> On Sun, Dec 13, 2015 at 6:15 PM, Feng ZhenPing >>>> <zhenpingfeng@gmail.com <mailto:zhenpingfeng@gmail.com>> >>>> >>>>> wrote:
     >>>>>>
     >>>>>> Check the line 7 and line 35, 38, 41. You will find the
    answer. The
     >>>>>> method only have 4 parameter.
     >>>>>>
     >>>>>> 在 2015年12月14日,上午9:49,Marc Chanliau
    <marc.chanliau@gmail.com <mailto:marc.chanliau@gmail.com>> 写道:

     >>>>>>
     >>>>>> 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 `<main>'
     >>>>>>
     >>>>>> 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
     >>>>>>
     >>>>>>
     >>>>>>
     >>>>>
     >>>>>
     >>>>
     >>>
     >>
     >

A user interface is usually such a pain in the arse to write that it's a
good idea to split it off into a module, or at least a class or two.

A good place to start with a problem like this is to think about what
classes you need. While there are different ways of skinning this cat, you
might for example have:

Questions: A question is associated to a correct answer.

Answers/Responses: An answer/response is a potential answer to a question

Rounds: A round consists of a question and n answers/responses (one of
the answers has to be correct) and return true or false depending on the
response entered.

Score: Number of rounds correctly answered.

The UI has to print rounds, get user response and print the score. Don't
worry about having classes that don't seem to do much especially because
the ruby library seems so powerful.

(Anyway, then you probably want to read in the questions and answers
from a text file.)