Hey everyone,

My problem is that I have a program which is to be used for teachers. One of the functions I am implementing is a SearchStudent function. Basically it checks a multidimensional array I created called MyClass[MaxSize,MaxGrade], MaxSize being the amount of students that can input into the program and MaxGrade being the number of grades the student has(it is defined as '6' so MaxGrade = 0 is for student IDs and MaxGrade = 1-6 being the actual grades stored). I already have it output all the grades, I just need it to take those grades it outputs for the specific student and average them so it can output those grades along with the average. The code is supplied below, thanks for any help you can provide.

#include <iostream>
#include <stdlib.h>
using namespace std;

#define MaxSize 5
#define MaxGrade 6

int i, x;
int student = 0;

float MyClass[MaxSize][MaxGrade];
int numstudents;

int AddStudent();
void PrintClassList();
int ShowClassAverage();
void ShowGrades();
void ShowHiLo();
void SearchStudent();
void DeleteStudent();
void ClearArray();


//Searches for Student
void SearchStudent(){

	float target;
	float sum;
	float avg;
	int flag;
	int p;

	// Search Attempt
	cout << endl << "Enter a Student ID to be found: ";
    cin >> target;

	for(i = 0; i < MaxSize; i++){

		for(x = 0; x < MaxGrade; x++){

			if(MyClass[i][x] == target){

				cout << endl << "Found Student ID Number: " << MyClass[i][x];

				for(p=1; p < MaxGrade; p++){
					cout << endl << endl << "Grade " << p << " is: " << MyClass[i][x+p] << endl;


				flag = 5;


	// Test to see if target was found.

	if(flag < 1){

		cout << "Student ID not found." << endl;
8 Years
Discussion Span
Last Post by Ancient Dragon

So what is the problem you are having? To get the average just add them up and divide by the number of grades -- 4th grade math.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.