
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 0.74 KB | hits: 10 | expires: Never
class Screen
def cls
puts ("\n" * 10)
puts "\a"
end
def pause
STDIN.gets
end
end
puts "How many years?"
#gets: gets the user input
#chomp: removes trailing \n
#to_i: converts to Fixnum(integer)
years = gets.chomp.to_i
#this will hold the total ammount
total_inches = 0
(1..years).each do |year|
(1..12).each do |month|
puts "how many inches did it rain this month" #here I ask for rainfall inches
STDIN.gets
month.chop!
#for the given month and add it to total_inches
puts "Year: #{year}, Month: #{month}"
secondinput = total_inches / month
puts "Number of Months = #{firstinput}"
puts "Average rainfall for month: #{secondinput}"
end
end