Question: Write a Ruby application that allows a user to input a series of 10 integers and determines and prints the largest integer. Your program should
Write a Ruby application that allows a user to input a series of 10 integers and determines and prints the largest integer. Your program should use at least the following three variables: a) counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed). b) number: The integer most recently input by the user. c) largest: The largest number found so far.
This is what I have so far, but I am struggling with part b (ost recent integer). Any suggestions or help would be greatly appreciated!
#Determine the Highest Value Application and Display Most Recent Input
#This application is designed to take a sequence of inputted numbers and determine to the user the output of the highest value and that of their most recent number input.
class Screen
def cls
puts (" " * 25)
puts "\a"
end
def pause
STDIN.gets
end
end
Console_Screen = Screen.new
num = [] #array to store user input
$counter = 1
loop do
puts "Please Enter Number " + $counter.to_s + " of a series of 10 numbers to determine the
largest."
# Console_Screen.pause
loop do
print "Please Press Enter:"
number = gets.chomp
num << number.to_i if number =~ /[0-9]/ #only writes to the array if it's a number
break if number =~ /[0-9]/ #only allow numbers
end
$counter += 1
break if $counter == 11
end
puts "Press Enter to have the numbers you have entered to be sorted and the largest displayed to you."
Console_Screen.pause
largest = num.max
puts "This is your largest number: " + largest.to_s
Console_Screen.pause
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
