A grade calculator. Everything works fine EXCEPT it does NOT display all the courses and grades average is off.

#include <iostream>
#include<iomanip>
using namespace std;
int numStudents2;

int main()
{
char letter;
cout <<"Welcome to Jessie's Academy Grade Calculator" <<endl;
cout <<"Enter number of students: ";
cin >> numStudents2;

const int numStudents = numStudents2;
string studentName[numStudents];
int numCourses[numStudents];
string courseName[numStudents];
double courseGrade[numStudents];
float aveGrade[numStudents];
double sumGrades=0;

for (int i = 0; i<numStudents; i++)
{
cout << "Student " << i+1 << " name: ";
cin >> studentName[i];
cout << "Number of courses taken: ";
cin >> numCourses[i];
for (int j = 0; j < numCourses[i]; j++)
{
cout << "Course name " << j+1 << ": ";
cin >> courseName[j];
cout << "Course grade " << j+1 << ": ";
cin >> courseGrade[j];
sumGrades =+ courseGrade[j];
}
aveGrade[i] = sumGrades / numCourses[i];


}

cout<<"\n\n********Grade Report*********\n" <<endl;

cout <<"STUDENT NAME" <<"\t" <<"# OF COURSES" <<"\t" <<"COURSE NAME" <<"\t" <<"GRADE" <<"\t" <<"AVERAGE"<< "\t\t" << "LETTER GRADE" <<endl;

for (int i = 0; i<numStudents; i++)
{
if ( (aveGrade[i] >= 90) && (aveGrade[i] <=100) )
{
letter = 'A';
}
else if ( (aveGrade[i] >= 80) && (aveGrade[i] <=89) )
{
letter = 'B';
}
else if ( (aveGrade[i] >= 70) && (aveGrade[i] <=79) )
{
letter = 'C';
}
else
{
letter = 'F';
}
cout << studentName[i]<< "\t\t"<< numCourses[i] << "\t\t" << courseName[i] << "\t\t" << courseGrade[i] << "\t" << aveGrade[i] << "\t\t" << letter<< "\n";

}


double max = aveGrade[0];
double min = aveGrade[0];
for (int i = 0; i < numStudents; i++)
{
if (max < aveGrade[i])
max = aveGrade[i];

if(min > aveGrade[i])
min = aveGrade[i];
}

cout<<"\n\nHighest Average: " << max;
cout<<"\nLowest Average: " << min;
return 0;
}









OUTPUT BELOW
***************************************************
Welcome to Jessie's Academy Grade Calculator
Enter number of students: 2
Student 1 name: Anne
Number of courses taken: 2
Course name 1: Math
Course grade 1: 89
Course name 2: English
Course grade 2: 92
Student 2 name: Billy
Number of courses taken: 2
Course name 1: Science
Course grade 1: 86
Course name 2: Physics
Course grade 2: 95


********Grade Report*********

STUDENT NAME # OF COURSES COURSE NAME GRADE AVERAGE LETTER GRADE
Anne 2 Science 86 46 F
Billy 2 Physics 95 47.5 F


Highest Average: 47.5
Lowest Average: 46
It wont compile as standard C++ (though the non-standard GNU dialect accepts it).
Use a vector instead https://cal-linux.com/tutorials/vectors.html

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>

int numStudents2;

int main()
{
    std::cin >> numStudents2;
    const int numStudents = numStudents2; // can't be evaluated at compile time
    std::string studentName[numStudents]; // error: ISO C++ forbids variable length array
}

http://coliru.stacked-crooked.com/a/f92f0e823d5f103f
sumGrades needs to be set to 0 for EACH student (i.e. within the i loop). At the moment you are accumulating it for all students.

courseGrade is something based on the j loop, not the student ( i loop).

Please use code tags.
You need 2d arrays to store the subject names/scores for all the students. Perhaps something like using standard C++ without vectors:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
using namespace std;

constexpr size_t maxStud {20};
constexpr size_t maxCrse {6};
constexpr double minGrde {0.0};
constexpr double maxGrde {100.0};

int main() {
	size_t numStudents{};

	cout << "Welcome to Jessie's Academy Grade Calculator\n";
	cout << "Enter number of students (max " << maxStud << "): ";
	cin >> numStudents;

	if (numStudents > maxStud) {
		cout << "Maximum students exceeded. " << maxStud << " used\n";
		numStudents = maxStud;
	}

	string studentName[maxStud];
	int numCourses[maxStud] {};
	string courseName[maxStud][maxCrse];
	double courseGrade[maxStud][maxCrse] {};
	double aveGrade[maxStud] {};
	double mxGrde {minGrde - 1};
	double mnGrde {maxGrde + 1};

	for (size_t i {}; i < numStudents; ++i) {
		double sumGrades{};

		cout << "Student " << i + 1 << " name: ";
		cin >> studentName[i];

		cout << "Number of courses taken (max " << maxCrse << "): ";
		cin >> numCourses[i];

		if (numCourses[i] > maxCrse) {
			cout << "Maximum courses exceeded. " << maxCrse << " used\n";
			numCourses[i] = maxCrse;
		}

		for (size_t j {}; j < numCourses[i]; ++j) {
			cout << "Course name " << j + 1 << ": ";
			cin >> courseName[i][j];

			do {
				cout << "Course grade " << j + 1 << " (" << minGrde << " - " << maxGrde << "): ";
				cin >> courseGrade[i][j];
			} while ((courseGrade[i][j] < minGrde || courseGrade[i][j] > maxGrde) && (cout << "Invalid grade\n"));

			sumGrades += courseGrade[i][j];
		}

		aveGrade[i] = sumGrades / numCourses[i];

		if (aveGrade[i] > mxGrde)
			mxGrde = aveGrade[i];

		if (aveGrade[i] < mnGrde)
			mnGrde = aveGrade[i];
	}

	cout << "\n\n********Grade Report*********\n";
	cout << "STUDENT NAME" << "\t" << "# OF COURSES" << "\t" << "COURSE NAME" << "\t" << "GRADE" << "\t" << "AVERAGE" << "\t\t" << "LETTER GRADE\n";

	for (size_t i {}; i < numStudents; ++i) {
		char letter {'A'};

		letter += aveGrade[i] < 90;	// B
		letter += aveGrade[i] < 80;	// C
		letter += aveGrade[i] < 70;	// D
		letter += aveGrade[i] < 60;	// E
		letter += aveGrade[i] < 50;	// F

		cout << studentName[i] << "\t\t" << numCourses[i] << "\t\t" << courseName[i][0] << "\t\t" << courseGrade[i][0] << "\t" << aveGrade[i] << "\t\t" << letter << "\n";

		for (size_t j {1}; j < numCourses[i]; ++j)
			cout << "\t\t\t\t" << courseName[i][j] << "\t\t" << courseGrade[i][j] << '\n';

		cout << '\n';
	}

	cout << "\n\nHighest Average: " << mxGrde;
	cout << "\nLowest Average: " << mnGrde;
}

Registered users can post here. Sign in or register to post.