Skip to content

Instantly share code, notes, and snippets.

@divoxx
Created September 23, 2010 23:43
Show Gist options
  • Select an option

  • Save divoxx/594614 to your computer and use it in GitHub Desktop.

Select an option

Save divoxx/594614 to your computer and use it in GitHub Desktop.
puts "Type 'end' at any point to calculate the average."
marks = []
sum = 0
while mark != "end"
print "Enter Mark: "
mark = gets.chomp
break if mark == "end"
begin
mark = Float(mark)
marks << mark
sum = sum + mark
rescue ArgumentError
puts "Invalid mark #{mark}"
end
end
average = sum / marks.size
puts "The Average grade of the class is #{average}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment