Created
August 6, 2011 03:08
-
-
Save christopherdolan/1128967 to your computer and use it in GitHub Desktop.
tiny little script to calculate a gpa in ruby
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
# a Hash of mappings between letter grade and GPA value | |
@grades = { | |
'a' => 4.0, | |
'b' => 3.0, | |
'c' => 2.0, | |
'd' => 1.0, | |
'f' => 0.0 | |
} | |
# a method for calculating a student's GPA | |
def calculate_gpa(student) | |
total = 0 | |
student.each do |grade| | |
total += @grades[grade] | |
end | |
total / student.size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment