Created
September 23, 2010 23:02
-
-
Save divoxx/594565 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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}" |
This file contains hidden or 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
| 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