Hello, with me is an assignment where am to create a code that can receive 10 grades and then give a grading letter attached to it accordingly as an output. I have worked on this code but on trying to run it does not give the expected input/ output which should be in multiples. Am only getting output as listed below:
Included is the code that I prepared.
Input:
95
100
99
96
98
97
94
94.5
90
88
the expected input/ output which should be in multiples.
Do not understand what you mean by "multiples".
The output you posted does not match your program. Your listed output is in lower case. Your program outputs upper case.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
#include <iostream>
constexpr size_t NoGrades {10};
char getLetter(double);
int main() {
double grades[NoGrades]{};
for (size_t g = 0; g < NoGrades; ++g) {
std::cout << "Enter mark for student " << g + 1 << ": ";
std::cin >> grades[g];
}
std::cout << '\n';
for (constauto& g : grades)
std::cout << g << "=" << getLetter(g) << '\n';
}
char getLetter(double grade) {
if (grade >= 95 && grade <= 100)
return'A';
if (grade >= 90 && grade <= 94.99)
return'B';
if (grade >= 85 && grade <= 89)
return'C';
if (grade >= 80 && grade <= 84)
return'D';
if (grade >= 75 && grade <= 79)
return'E';
if (grade >= 40 && grade <= 74)
return'F';
return'X';
}
Enter mark for student 1: 95
Enter mark for student 2: 100
Enter mark for student 3: 99
Enter mark for student 4: 96
Enter mark for student 5: 98
Enter mark for student 6: 97
Enter mark for student 7: 94
Enter mark for student 8: 94.5
Enter mark for student 9: 90
Enter mark for student 10: 88
95=A
100=A
99=A
96=A
98=A
97=A
94=B
94.5=B
90=B
88=C