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;
}

the only problem I have is getting the highest average grade.

double get_highest_average_grade(int grades[8][3]);
{
     double averages[8];

     //outside loop
          //inside loop       
             //add 3 elements 
             //divide by 3
             //store result in averages[]

     //Begin Loop      
          //compare current element to next element of the averages[] array
          //save the highest of the two in a temp variable

      //return temp
}

Edited 5 Years Ago by Clinton Portis: n/a

thanks i have fix it a little this is my code now

#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;

	string name[numberOfstudents] = {"Isabel", "Steve", "Michael",
									"James", "Jennifer", "Billy",
									"Brenda", "Jesus"};
	int 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";
	
	double total;
	double average;
	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;
	}
	
	
	int highestAverage = grades[numberOfstudents][numberOfgrades];

	for(int i = 0; i < numberOfstudents; i++)
	{
		for(int j = 0; j < numberOfgrades; j++) 
		{
			if(grades[i][j] > highestAverage)
			{
				highestAverage = grades[i][j];
			}
		} 
	}
	
	cout << "\nThe student with the highest average grade is " 
		<< name(need help here) << " and the average is " << highestAverage << endl;
	
	return 0;
}

but now i get the highest grade instead of the highest average grade

This article has been dead for over six months. Start a new discussion instead.