Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save divoxx/594565 to your computer and use it in GitHub Desktop.
array = []
loop do
print "Enter Mark: "
case mark = gets.chomp
when Integer
array << mark.to_f
when "end"
break
else
puts "Invalid mark #{mark}"
end
end
sum = 0
array.each { |m| sum += m }
average = sum / array.size
puts "The Average grade of the class is #{average}"
sum = 0
num = 0
loop do
print "Enter Mark: "
case mark = gets.chomp
when Integer
sum += mark.to_f
num += 1
when "end"
break
else
puts "Invalid mark #{mark}"
end
end
average = sum / num
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