Skip to content

Instantly share code, notes, and snippets.

@christopherdolan
Created August 6, 2011 03:08
Show Gist options
  • Save christopherdolan/1128967 to your computer and use it in GitHub Desktop.
Save christopherdolan/1128967 to your computer and use it in GitHub Desktop.
tiny little script to calculate a gpa in ruby
# 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