Making the Grade Test 10 Fail

What is wrong with this code? Test 11 and 12 pass. Test 10 failed.

// Create a list of grade thresholds based on the provided highest grade.
std::array<int, 4> letter_grades(int highest_score) {
    double lowest = 41;
    std::array<int, 4> grades;
    double average = (highest_score - lowest) / 4.0;
    grades[3] = highest_score - static_cast<int>(average);
    grades[2] = grades[3] - static_cast<int>(average);
    grades[1] = grades[2] - static_cast<int>(average);   
    grades[0] = lowest;
    
    return grades;
}

Test 10 output:

FAILED:
  REQUIRE( expected == actual )
with expansion:
  { 41, 56, 71, 86 } == { 41, 58, 72, 86 }
at /tmp/making-the-grade/making_the_grade_test.cpp:93
  1. Do you understand what the test is running?
  2. Do you understand what the tests expect she why those are the correct values?
  3. Do you understand what your code is returning for this test and why it is the wrong value?
  4. Give this input, can you walk through your code and figure out why your code is returning the incorrect values it is generating?
1 Like

@IsaacG

  1. Yes
  2. Yes
  3. Yes
  4. I am trying to.

I reverse engineered what I saw in the test to figure out how to configure the function. Something is slightly off so test 10 fails.

With those inputs, what is the value of each variable on each line?

1 Like

@IsaacG Thanks!
I could have actually figured this out with just a few print statements.

As soon as I ask a question in the forum I figure out how to do what I need to do.

grades[2] = grades[3] - static_cast<int>(std::ceil(average));
grades[1] = grades[2] - static_cast<int>(std::ceil(average));

I have passed test 10.

Is there no one to mentor C++? I have not had anyone mentor me in C++ yet.

Nicely done!

Iā€™m pretty sure there are some C++ mentors but the C++ queue does look pretty backed up at the moment :frowning:

2 Likes