Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Screen
  2.   def cls
  3.     puts ("\n" * 10)
  4.     puts "\a"
  5.   end
  6.  
  7.   def pause
  8.     STDIN.gets
  9.   end
  10. end
  11.  
  12. puts "How many years?"
  13.  
  14. #gets: gets the user input
  15. #chomp: removes trailing \n
  16. #to_i: converts to Fixnum(integer)
  17. years = gets.chomp.to_i
  18.  
  19. #this will hold the total ammount
  20. total_inches = 0
  21.  
  22. (1..years).each do |year|
  23.     (1..12).each do |month|
  24.        puts "how many inches did it rain this month" #here I ask for rainfall inches
  25.        STDIN.gets
  26.        month.chop!
  27.        
  28.         #for the given month and add it to total_inches
  29.         puts "Year: #{year}, Month: #{month}"
  30.        
  31.         secondinput = total_inches / month
  32.        
  33.       puts "Number of Months = #{firstinput}"
  34.       puts "Average rainfall for month: #{secondinput}"
  35.     end
  36. end