954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Student Average With Multidimensional Array

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;
	}
}
nagha3
Newbie Poster
1 post since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
jencas
Posting Whiz
366 posts since Dec 2007
Reputation Points: 395
Solved Threads: 71
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You