### I keep getting a run time error but the code compiles and opens??

i dont understand

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465`` `````` //help from Chegg tutors //Ayila Reese #include using namespace std; char scoreToGrade(double score) { char grade = 'F'; if (score >= 90.0) { grade = 'A'; } else if (score >= 80.0) { grade = 'B'; } else if (score >= 70.0) { grade = 'C'; } else if (score >= 60.0) { grade = 'D'; } return grade; } int main(int argc, char** argv) { double total_score = 0; double lowest_score = DBL_MAX; double highest_score = DBL_MIN; double score; double scores[5]; int report[5]; char letters[] = { 'A', 'B', 'C', 'D', 'F' }; for (int i = 0; i < 5; i++) { report[i] = 0; } cout << "Please enter your scores for the following 5 homework assignments:\n"; for (int i = 0; i < 5; i++) { cout << "HW" << i + 1 << ": "; cin >> score; if (score < lowest_score) { lowest_score = score; } if (score > highest_score) { highest_score = score; } total_score += score; scores[i] = score; report[scoreToGrade(score) - 'A'] += 1; } double average = total_score / 5.0; cout << "Your average score is " << scoreToGrade(average) << " which is a " << scoreToGrade(average) << ".\n"; cout << "Your letter grade report is : \n"; for (int i = 0; i < 5; i++) { cout << report[i] << " " << letters[i] << "\n"; } cin.get(); return 0; }``````
because of this;
`report[scoreToGrade(score) - 'A'] += 1;`
a grade of 'F' will generate a subscript error as indices are 0..4 but 'F'-'A' = 5.

Topic archived. No new replies allowed.