Ronald F. wrote in post #1185572:
With “force the user to input text”, I guess you mean that the user
doesn’t just press the return key, but also types something in addition,
and that you are concerned with the user response for
Console_Screen.pause. Right?
You didn’t show the code for Console_Screen.pause, but I assume that you
will there also do some STDIN.gets, so why don’t you simply look at what
has been returned?
Ronald,
That is what I meant why “force the user to input text.” And I am
concerned with the input for Console_Screen.pause. I don’t understand
what you mean for the code for Console_Screen.pause tho. I’ve pasted the
whole script below. I don’t expect you to help me with the whole thing
but this is about 4 weeks into my class and I’m unsure of what to
provide to answer your question.
class Screen
def cls
puts ("\n" * 25)
puts “\a”
end
def pause
STDIN.gets
end
end
class Test
def display_greeting
Console_Screen.cls
print "\t\t Welcome to the Ruby Typing Challenge game!" +
"\n\n\n\n\n\n\n\n\n\n\n\n\nPress Enter to " +
"continue. \n\n: "
Console_Screen.pause
end
def display_instructions
Console_Screen.cls
puts "\t\t\tInstructions:\n\n"
#Altered the instructions to provide grading instructions
puts %Q{ This test consists of a series of 10 typing
challenges. The Challenge sentences are presented
one at a time. To respond correctly, you must retype
each sentence exactly as shown and press the Enter key.
Your grade is presented as a letter grade with 9-10
correct being an A, 8 a B, 7 a C, 6 is a D and anything
less being a F. Your grade will be displayed at the end
of the test.
\n\n\n\n\n\n
Press Enter to continue\n\n}
Console_Screen.pause
end
def present_test(challenge)
Console_Screen.cls
print challenge +"\n\n: "
result = STDIN.gets
result.chop!
if challenge == result then
$noRight += 1
Console_Screen.cls
print "Correct!\n\nPress Enter to continue."
Console_Screen.pause
else
Console_Screen.cls
#Ex 4. Will present the incorrectly typed message above the
expected result.
print “Incorrect!\n\nPress Enter to continue.” + “\n\n”
print result + “\n\n”
print challenge
Console_Screen.pause
end
end
def determine_grade
Console_Screen.cls
#Increased the passing score from 3 to 6.
# if $noRight >= 6 then
answer = $noRight
case
when (answer.between?(9,10))
puts "A"
when answer == 8
puts "B"
when answer == 7
puts "C"
when answer == 6
puts "D"
when (answer.between?(0,5))
puts "F"
if answer >=6
print "You retyped " + $noRight.to_s + " sentence(s) correctly.
"
puts “You have passed the typing test!\n\nPress Enter to
continue.”
else
print "You retyped " + $noRight.to_s + " sentence(s) correctly.
"
puts “You have failed the typing test!\n\nPress Enter to
continue.”
end
end
end
Main Script Logic -----------------------------------------------
$noRight = 0
Console_Screen = Screen.new
Typing_Test = Test.new
Typing_Test.display_greeting
Console_Screen.cls
print "Would you like to test your typing skills? (y/n)" +
"\n\n"
answer = STDIN.gets
answer.chop!
until answer == “y” || answer == “n”
Console_Screen.cls
print "Would you like to test your typing skills? (y/n)\n\n: "
answer = STDIN.gets
answer.chop!
end
if answer == “n”
Console_Screen.cls
puts "Okay, perhaps another time.\n\n"
else
Typing_Test.display_instructions
#Extended the typing test to cover 10 Sentences from 5 for Ex 1
Typing_Test.present_test"In the end there can be only" +
" one."
Typing_Test.present_test “Once a great plague swept” +
" across the land"
Typing_Test.present_test “Welcome to the principles of Ruby”
Typing_Test.present_test “There are very few problems in” +
" the world that enough moms cannot fix."
Typing_Test.present_test “Perhaps today is a good day to” +
" die. Fight beside me and let us die together"
Typing_Test.present_test “I sure hope I get an A in this class”
Typing_Test.present_test “Full time employment does not mix
well” +
" well full time student status"
Typing_Test.present_test “May of 2018 cannot come quick
enough”
Typing_Test.present_test “Life will be simpler once a student
graduates”
Typing_Test.present_test “College will be worth it after
getting that degree”
Typing_Test.determine_grade
Console_Screen.pause
Console_Screen.cls
puts “Thank you for taking the Ruby Typing Challenge.\n\n”
end
end