Oct 7, 2021 at 12:14pm Oct 7, 2021 at 12:14pm UTC
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 Oct 7, 2021 at 3:49pm Oct 7, 2021 at 3:49pm UTC
Oct 7, 2021 at 12:35pm Oct 7, 2021 at 12:35pm UTC
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 Oct 7, 2021 at 12:37pm Oct 7, 2021 at 12:37pm UTC
Oct 7, 2021 at 1:37pm Oct 7, 2021 at 1:37pm UTC
The question did not ask for an average at all. And it was clear what to do with invalid data.
Last edited on Oct 7, 2021 at 1:39pm Oct 7, 2021 at 1:39pm UTC
Oct 7, 2021 at 3:39pm Oct 7, 2021 at 3:39pm UTC
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.
Oct 7, 2021 at 3:49pm Oct 7, 2021 at 3:49pm UTC
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 Oct 7, 2021 at 5:12pm Oct 7, 2021 at 5:12pm UTC
Oct 7, 2021 at 7:16pm Oct 7, 2021 at 7:16pm UTC
Bullshit! You rewrote the opening post to "solved" in a very lame attempt to hide you getting help.
Oct 7, 2021 at 7:19pm Oct 7, 2021 at 7:19pm UTC
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.