Skip to content

Instantly share code, notes, and snippets.

@shadow1349
Created August 24, 2019 21:18
Show Gist options
  • Save shadow1349/e6bac2f2fd3c00d66da5493af8190b58 to your computer and use it in GitHub Desktop.
Save shadow1349/e6bac2f2fd3c00d66da5493af8190b58 to your computer and use it in GitHub Desktop.
namespace Grader.Service
{
public class GradeConverter
{
/// <summary>
/// This function will take in a positive integer representing a grade percentage
/// and return the letter grade corresponding to that percentage.
/// </summary>
public char GetLetterGrade(int grade)
{
if (grade >= 90)
{
return 'A';
}
// As per the requirements we will always include the lower bound number
// in the middle cases
if (grade < 90 && grade >= 80)
{
return 'B';
}
if (grade < 80 && grade >= 70)
{
return 'C';
}
if (grade < 70 && grade >= 60)
{
return 'D';
}
if (grade < 60)
{
return 'F';
}
// this should never happen, but if it does then we know something is wrong.
throw new System.Exception("No letter grade found for that percentage");
}
}
}
We need a function that converts a percentage into a letter grade.
The mapping should be as follows:
- 90 and above (including 90) should be given an A
- 80 - 90 (including 80) should be given a B
- 70 - 80 (including 70) should be given a C
- 60 - 70 (including 60) should be given a D
- Anything below (but NOT including 60) should be given an F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment