Skip to content

Instantly share code, notes, and snippets.

@iamsok
Created August 12, 2014 18:44
Show Gist options
  • Save iamsok/fcba56e0a2562cf11fcb to your computer and use it in GitHub Desktop.
Save iamsok/fcba56e0a2562cf11fcb to your computer and use it in GitHub Desktop.
def average(grades)
grades.map! {|num| num.to_i}
grades.inject(0) {|sum, n| sum += n} / grades.size
end
puts 'Enter grades (one per line, type "done" on a new line when finished):'
grades = Array.new
grade = gets.chomp
while grade.downcase != "done"
grades << grade
grade = gets.chomp
end
if average(grades) >= 60
puts "passed"
else
puts "failed"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment