Hello everyone, my assignment is to calculate each student's test average and final letter grade from a class of 20 students with 3 tests. The scores for each test are located in the text files that I am attaching.
I have worked on this code for some time now, but in the output, all of the averages are incorrect.
Here is an example of what a section of an output might look like:
Student #1:
Class Average: 95
Final Grade: A
But I want to display this for each of the 20 students. Instead, it gave me a class average of -57283, which is obviously wrong.
Here is my code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int score1[20], score2[20], score3[20];
int grade, num, student;
int avg;
char letter;
ifstream inp1, inp2, inp3;
inp1.open("test1.txt");
inp2.open("test2.txt");
inp3.open("test3.txt");
for(student=1; student<21; student++)
{
num=1;
for(grade=0; grade<num; grade++)
{
inp1>>score1[grade];
inp2>>score2[grade];
inp3>>score3[grade];
avg=(score1[grade]+score2[grade]+score3[grade])/3;
}
if(90<=avg)
letter='A';
else if(80<=avg<90)
letter='B';
else if(70<=avg<80)
letter='C';
else if(60<=avg<70)
letter='D';
else
letter='F';
cout<<"Student #"<<num<<": "<<endl;
cout<<"Class Average: "<<avg<<endl;
cout<<"Final Grade: "<<letter<<endl;
cout<<endl;
num++;
}
char holdscr;
cin>>holdscr;
inp1.close();
inp2.close();
inp3.close();
return 0;
}