Good evening everyone,
I have posted my code below but am unable to determine what is causing a
persistent “Dynamic constant assignment” error at
“Console_Screen = Screen.new” and “SQ = Quiz.new”
on line 144 and 146. Any help or insight at all would be great. I’ve had
this issue before and it was fixed with “end”. I went through and to me
it seems like all of the end statements are in the appropriate place.
class Screen
def cls
puts (“\n” * 25)
puts “\a”
end
def pause
#Pauses the display until the player presses the enter
key
STDIN.gets
end
class Quiz
def display_greeting
Console_Screen.cls #Clears display
print “\t\t Welcome to the SUperman Movie Trivia Quiz!” +
“\n\n\n\n\n\n\n\n\n\nPress Enter to” +
“continue.”
Console_Screen.pause #Pauses the game
end
def display_instructions #Method to present quiz instructions
Console_Screen.cls
puts "INSTRUCTIONS:\n\n" #Displays a heading
puts "You will be presented with a series of" +
"multiple-choice"
puts "questions. To answer a question, type in" +
"the letter of"
puts " the corresponding answer and press the" +
"Enter Key. Your"
puts "grade will be displayed at the end of the" +
"test\n\n\n"
puts "Good luck!\n\n\n\n\n\n\n"
print "Press Enter to continue."
Console_Screen.pause #Pause the game
end
def disp_q(question, q_A, q_B, q_C, q_D, answer)
#loop until a valid answer is input
loop do
Console_Screen.cls
#formats the display of the questions
puts question + "\n\n"
puts q_A
puts q_B
puts q_C
puts q_D
print "\nType the letter representing your answer:"
reply = STDIN.gets #collect the answer
reply.chop!
#Analyze the input
if answer == reply then
$noRight += 1
end
if reply == "a" or reply == "b" or reply =="c" or
reply == "d" then
break
end
end
#Method for grading the quiz
def determine_grade
Console_Screen.cls
#To pass they must answer 3 questions correctly
if $noRight >= 3 then
print "You correctly answered " + $noRight.to_s + "
question(s)."
puts "You have passed the \nSuperman Movie Trivia" +
"Quiz!\n\n"
puts "You have earned a rank of: Good Citizen" if
$noRight == 3
puts "You have earned a rank of: Side Kick"
if $noRight == 4
puts "You have earned the rank of: SuperHero"
if $noRight == 5
print "\n\nPress Enter to continue."
else #they failed
print "You missed" + (5 - $noRight).to_s +
"questions."
puts "You have failed the Superman Movie Trivia Quiz."
puts "Perhaps you should watch the movies again before
returning to"
puts "retake the quiz"
print "\n\nPress Enter to continue"
end
Console_Screen.pause
def display_credits
Console_Screen.cls
puts"\t\tThank you for taking the SUPERMAN MOVIE TRIVIA
QUIZ!\n\n\n\n"
puts "\n\t\t\t Developed by Glenn B Chamberlain\n\n"
puts "\t\t\t\t Copyright 2017\n\n"
puts "\t\t\tURL:
http://www.glennisthebestprogrammerever.com\n\n\n\n"
end
#Main Script
Logic----------------------------------------------------------------
#Keep track of the number of correct answers
$noRight = 0
#Where the problem is shown when I try to run the code-------------
Console_Screen = Screen.new
SQ = Quiz.new
#----------------------------------------------------------------
#Execute the display_greeting method
SQ.display_greeting
answer = ""
#loop until the play enters y or n only
loop do
Console_Screen.cls
print "Are you ready to take the quiz? (y/n): "
answer = STDIN.gets
answer.chop!
break if answer == "y" || answer == "n"
#analyze the players input
if answer == "n"
Console_Screen.cls
puts "Okay, perhaps another time.\n\n"
else
SQ.display_instructions #executes the
display_instructions method
#execute the disp_q method and pass it arguments
(questions, answers and correct answers)
SQ.disp_q("What is the name of the Daily Planet's ace" +
"photographer?", "a. Jimmy Olsen", "b. Clark Kent", +
"c. Lex Luthor", "d. Lois Lane", "a")
#Call upon the disp_q method and pass it the second questions
SQ.disp_q("What is the name of Clark Kents home town?",
"a. Metropolis", "b. Gotham City", "c.Smallville",
"d. New York", "c")
SQ.disp_q("In which movie did Superman battle" +
"General Zod?", "a. Super", "b. Superman II",
"c. Superman III", "d. Superman IV", "b")
SQ.disp_q("What is the name of Superman's father?",
"a. Nimo","b. Jarrell", "c. Lex Luthor",
“d.Krypton”,“b”)
SQ.disp_q("Where had Superman been at the start of "
-
"Superman Returns?", "a. Moon", "b. Fortress of Solitude", "c. Earth's Core", "d. Krypton", "d") #call up the determine_grade method to display the grade SQ.determine_grade SQ.display_credits end