Need help with finding Array Median and Mode of values?
Posted on 2006-11-06
I'm having trouble with two things:
This is what the book is asking of me "Write a program that can be used to gather statistical data about the number of movies college students see in a month.
The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user
to enter the number of movies each student has seen. The program should then calculate the average, median and mode the values entered.
I have created the program but I am stuck with showing the results. As of right now it shows the average, and I think I might be able to do the median by continuing
looking at some book samples. But the part that get's me the most and have difficult finding is "and mode the values entered."
Thanks in advance for your help!
using namespace std;
int main ()
double *movies, total = 0, average;
cout << "How many students were surveyed? \n";
cin >> numStudents;
movies = new double[numStudents];
cout << "Enter the number of movies for each student. \n";
for (count =0; count < numStudents; count ++)
cout << "Student " << (count + 1) << ": ";
cin >> movies[count];
for (count = 0; count < numStudents; count++)
total += movies[count];
average = total / numStudents;
cout << setprecision(2);
cout << fixed << showpoint;
cout << "Average: " << average << endl;
delete  movies;