Using function

Question: I honestly have no idea how to answer test #1, it only needs one input and will output one when the question is asking the user will input ten (10) consecutive numeric grades that may or may not have a decimal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <array>
#include <iomanip>
char getLetterGrade(double);
using namespace std;
int main(){
    const int students_number = 10;
    array<double, students_number> grades;
    array<char, students_number> letters;
    for(double & grade : grades)
        cin >> grade;
    for(size_t i = 0; i < students_number; ++i)
        letters[i] = getLetterGrade(grades[i]);
    for(size_t i = 0; i < students_number; ++i)
        cout << fixed << setprecision(2) << grades[i] << "=" << letters[i] << endl;
    return 0;
}
char getLetterGrade(double grade){
    if(grade >= 95 && grade <=100) return 'A';
    if(grade > 89 && grade< 95) return 'B';
    if(grade > 84 && grade< 90) return 'C';
    if(grade > 79 && grade< 85) return 'D';
    if(grade > 75 && grade< 80) return 'E';
    if(grade > 40 && grade< 76) return 'F';
    return 'X';
}


Test #1

--- Input ---

-100

--- Program output ---

-100.00=X

0.00=X

0.00=X

0.00=X

0.00=X

0.00=X

0.00=X

0.00=X

0.00=X

0.00=X

--- Expected output (text)---

-100.00=X
Last edited on
test 1 is checking what it does when they give invalid data.
you don't handle that... you should NOT average invalid data into the result .. did they not give any instructions on what to DO when you get invalid data? It does say only process the output if you get all 10, so if you get a bad input, maybe they want you to stop right away.

Last edited on
@jonnin the thing is for Test #3 at the start of the input is actually invalid but it still continues?

Test #3
https://prnt.sc/1v5q9qf
The question did not ask for an average at all. And it was clear what to do with invalid data.
Last edited on
Do NOT delete your original question, kazeroth900. Doing that is rude and no one else can possibly learn from the exchange.

You are a waste of time now and a thief.
Hi, I was editing my question to be more understandable as my code wasn't complete as I say that's why most of the answers here weren't able to answer my question at all.

Here's the answer to my queston:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <array>
#include <iomanip>
char getLetterGrade(double);
using namespace std;
int main(){
    const int students_number = 10;
    array<double, students_number> grades;
    array<char, students_number> letters;
    for(double & grade : grades){
    	cin >> grade;
    	for(size_t i = 0; i < students_number; ++i){
    		letters[i] = getLetterGrade(grades[i]);
    		cout << fixed << setprecision(2) << grades[i] << "=" << letters[i] << endl;
    		if(grade==0){
    			break;
			}
		}
	}
	return 0;
}
char getLetterGrade(double grade){
    if(grade >= 95 && grade <=100) return 'A';
    if(grade > 89 && grade< 95) return 'B';
    if(grade > 84 && grade< 90) return 'C';
    if(grade > 79 && grade< 85) return 'D';
    if(grade > 75 && grade< 80) return 'E';
    if(grade > 40 && grade< 76) return 'F';
    return 'X';
    
}
Last edited on
Bullshit! You rewrote the opening post to "solved" in a very lame attempt to hide you getting help.
Just leave your posts unedited, others can then see if they have same/similar questions and the follow-up replies. Editing posts renders any assistance you received as being meaningless.
Topic archived. No new replies allowed.