Printing out letter grade for class?

Without using any selections or loops, is there any other way you guys can hint me where I can print out a letter grade for each student. Generally speaking, another technique!

Student average: Letter Grade:
89 B
A lookup table. Why wouldn't you want to use 'if' statements and loops?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int main()
{
    char grades[] = { 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //0-9
                      'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //10-19
                      'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //20-29
                      'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //30-39
                      'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //40-49
                      'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', //50-59
                      'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', //60-69
                      'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', //70-79
                      'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', //80-89
                      'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', //90-99
                      'A' };                                            //100

    int grade = 89;
    std::cout << "Student average: " << grade << "\t\tLetter Grade: " << grades[grade] << std::endl;
    return 0;
}
Last edited on
We can use a if and the selection loops; however, as a challenge, I have been asked not to use the loops.
Topic archived. No new replies allowed.