Created
August 12, 2014 18:44
-
-
Save iamsok/fcba56e0a2562cf11fcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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