Arrays issue involving mean and median

The user is supposed to be able to enter the student's grades, and have the program output the median and mean. For some reason mine won't run and I keep getting the error "error C3861: 'median': identifier not found" Can anyone help me fix this issue?


#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

//function prototypes
void mean(int [], int num);
void meadian(int [], int num);
void sort(int[], int);

int _tmain(int argc, _TCHAR* argv[])
{
double numStudents = 0;
float total = 0;
//declare array
int grades[100] = { 0 };
int i;

cout << "Enter the number of students who have taken the exam: " << endl;
cin >> numStudents;

//store data in array
for (int i = 0; i < numStudents; i++)
{
cout << "Enter the student's grade ";
cout << i + 1 << ": ";
cin >> grades[i];
while (grades[i] < 0 || grades[i]>100)
{
cout << "Invalid input. Please enter a value between 0 and 100." << endl;
cout << "\nPlease reenter grade " << i + 1 << ": ";
cin >> grades[i];
}//end while
}//end for

sort(grades, i);

system("pause");
}

void mean(int grades_new[], int num)
{
//get total and calculate mean
float total=0;
for (int i = 0; i < num; i++)
{
total = +grades_new[i];
}
cout << "The mean of the grades is " << total / num << endl;

median(grades_new, num);

}

void median(int grades_new[], int num)
{
//calculate the median
if (num % 2 != 0)//the number is odd
{
int temp = ((num + 1) / 2) - 1;
cout << "The median of the grades is " << grades_new[temp] << endl;
}
else
{
cout << "The median of the grades is " << grades_new[(num / 2) - 1] << " and " << grades_new[num / 2] << endl;
}
}

void sort(int grades_new[], int num)
{
//arrange values
for (int x = 0; x < num; x++)
{
for (int y = 0; y < num - 1; y++)
{
if (grades_new[y]>grades_new[y + 1])
{
int temp = grades_new[y + 1];
grades_new[y + 1] = grades_new[y];
grades_new[y] = temp;
}
}
}
median(grades_new, num);
}
Last edited on
At first glance, the error is telling you that you've tried to access a function which is not defined. Your problem is that within main, you're calling "meadian" when your function is actually named "median." Just a simple spelling mistake really. ;P
Topic archived. No new replies allowed.