Computing & Information Systems    Department Search CIS Site      Tutorials

## Software Design Using C++

### Review of Decision Statements

First, we repeat the description of the problem: Write a C++ function that is given an integer grade (such as 90, 84, 66) and sends back the corresponding letter grade (such as A, B, D) in the function name. Return the letter I for any invalid grade number.

Here are possible answers to this problem. Click on the one that you think best answers the question.

 `````` /* Given: NumGrade A numeric grade (whole number). Task: To find the corresponding letter grade. Return: This letter grade in the function name. */ char LetterGrade(int NumGrade) { if (NumGrade > 100) return 'I'; else if (NumGrade > 90) return 'A'; else if (NumGrade > 80) return 'B'; else if (NumGrade > 70) return 'C'; else if (NumGrade > 60) return 'D'; else if (NumGrade > 0) return 'F'; else return 'I'; } ``````

 `````` /* Given: NumGrade A numeric grade (whole number). Task: To find the corresponding letter grade. Return: This letter grade in the function name. */ char LetterGrade(int NumGrade) { if (NumGrade > 100) return 'I'; else if (NumGrade >= 90) return 'A'; else if (NumGrade >= 80) return 'B'; else if (NumGrade >= 70) return 'C'; else if (NumGrade >= 60) return 'D'; else if (NumGrade >= 0) return 'F'; else return 'I'; } ``````

 `````` /* Given: NumGrade A numeric grade (whole number). Task: To find the corresponding letter grade. Return: This letter grade in the function name. */ char LetterGrade(int NumGrade) { char Ch; if (NumGrade > 100) Ch = 'I'; if (NumGrade >= 90) Ch = 'A'; if (NumGrade >= 80) Ch = 'B'; if (NumGrade >= 70) Ch = 'C'; if (NumGrade >= 60) Ch = 'D'; if (NumGrade >= 0) Ch = 'F'; if (NumGrade < 0) Ch = 'I'; return Ch; } ``````

 `````` /* Given: NumGrade A numeric grade (whole number). Task: To find the corresponding letter grade. Return: This letter grade in the function name. */ char LetterGrade(int NumGrade) { if (NumGrade > 100) return 'I'; if (NumGrade >= 90) return 'A'; if (NumGrade >= 80) return 'B'; if (NumGrade >= 70) return 'C'; if (NumGrade >= 60) return 'D'; if (NumGrade >= 0) return 'F'; return 'I'; } ``````

 `````` /* Given: NumGrade A numeric grade (whole number). Task: To find the corresponding letter grade. Return: This letter grade in the function name. */ char LetterGrade(int NumGrade) { char Ch; Ch = 'I'; // unless we change it below if ((NumGrade >= 90) && (NumGrade <= 100)) Ch = 'A'; if ((NumGrade >= 80) && (NumGrade < 90)) Ch = 'B'; if ((NumGrade >= 70) && (NumGrade < 80)) Ch = 'C'; if ((NumGrade >= 60) && (NumGrade < 70)) Ch = 'D'; if ((NumGrade >= 0) && (NumGrade < 60)) Ch = 'F'; return Ch; } ``````