Question: I need help fixing this code. #include #include #include using namespace std; // define a struct to hold student records struct Student { string name;

I need help fixing this code.

#include #include #include

using namespace std;

// define a struct to hold student records struct Student { string name; int test1; int test2; int test3; int test4; int test5; double average; char grade; };

// function to calculate the average score and letter grade void calculateGrade(Student& student) { double sum = student.test1 + student.test2 + student.test3 + student.test4 + student.test5; student.average = sum / 5.0; if (student.average >= 90) { student.grade = 'A'; } else if (student.average >= 80) { student.grade = 'B'; } else if (student.average >= 70) { student.grade = 'C'; } else if (student.average >= 60) { student.grade = 'D'; } else { student.grade = 'F'; } }

int main() { // open the input file ifstream inputFile("students.txt"); if (!inputFile) { cerr

// create the output file ofstream outputFile("output.txt"); if (!outputFile) { cerr

// read the student records from the input file and output to console and output file Student student; cout > student.name >> student.test1 >> student.test2 >> student.test3 >> student.test4 >> student.test5) { calculateGrade(student); cout

// close the input and output files inputFile.close(); outputFile.close();

return 0; }

When I run the code, it only outputs this:

I need help fixing this code. #include #include #include using namespace std;

The txt file data is:

Norman M. Richard 88 90 89 97 93

Alfred G. Pena 67 63 61 67 60

Hema A. Garcia 77 71 79 68 70

Omar T. Garza 83 80 81 89 85

Nancy M. Zamora 55 56 57 60 63

C++

Name Test1 Test2 Test3 Test4 Test5 Avg Grade

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!