Challenge 2: Letter Grade to GPA

Test your knowledge by writing a subroutine to calculate the sum of two numbers.

Problem statement

There are many school systems that give standardized GPA points instead of letter grades and vice versa. To bring all these institutions on the same grade scale, we have hired you! Your job is to take a letter grade and change it to the required GPA point.

Write a method called gpaPoint that takes in a string value and returns the correct decimal GPA point, with respect to the scale given below:

  • A+: 4
  • A: 4
  • A-: 3.7
  • B+: 3.3
  • B: 3
  • B-: 2.8
  • C+: 2.5
  • C: 2
  • C-: 1.8
  • D: 1.5
  • F: 0

If any other grade is given, simply return a -1.

Hint: Revise conditionals and see what helps keep your code short and brief.

Input

A string grade.

Output

A floating-point value corresponding to the letter grade.

Sample input

B-

Sample output

2.8

Coding exercise

Write your code in the code widget below. If you don’t get it right, don’t worry; the solution is also given.

sub gpaPoint{
# Write your code here
return -9;
}