Write a program that uses two parallel arrays to store student names and their grades. It should use an array of strings that hold the names and a two-dimensional array of integers for grades. Use nested loop to add individual student grades and get the average grade of each. The program should produce a report that displays list of student names and grade average along with the name of student that has the highest average grade.
Use the following lists for student names and their grades.
Isabel (92, 95, 94), Steve (99, 76, 68), Michael (89, 70, 85), James (80, 75, 71), Jennifer (78, 77, 93), Billy (93, 91, 89), Brenda (82, 95, 71), Jesus (98, 82, 84)
The output should appear as shown below:
Student Name Grade
Isabel (display average here)
Steve
Michael
James
Jennifer
Billy
Brenda
Jesus
The student with the highest average grade is ____ and the average is ____.(This is where i need help).
So far i got the list of the student name with their grades average that i'm supposed to display the only problem I have is getting the highest average grade. I have followed some examples from the book but so far I keep getting errors. This is the error i get error C2108: subscript is not of integral type. Thanks!!
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int numberOfstudents = 8;
const int numberOfgrades = 3;
double total;
double average;
string name[numberOfstudents] = {"Isabel", "Steve", "Michael",
"James", "Jennifer", "Billy",
"Brenda", "Jesus"};
double grades[numberOfstudents][numberOfgrades] = {{92,95,94},
{99,76,68},
{89,70,85},
{80,75,71},
{78,77,93},
{93,91,89},
{82,95,71},
{98,82,84}};
cout << "Student Name Grade\n";
cout << "------------" << setw(14) << "-------\n";
for (int student = 0; student < numberOfstudents; student ++)
{
total = 0;
for (int col = 0; col < numberOfgrades; col++)
total += grades[student][col];
average = total / numberOfgrades;
cout << setw(9) << left << name[student];
cout << setw(14) << right << average << endl;
}
double rows;
double highestAverage=0;
double topStudent;
for( rows = 0; rows < average; rows++)
{
if( grades[rows] > highestAverage)
{
highestAverage = grades[rows];
topStudent = rows;
}
}
{
cout <<"\nThe student with the highest average grade is "
<< name[topStudent] <<" and the average is " << grades[topStudent] << endl;
}
return 0;
}