Hi. I am creating a program for class that can be used to gather statisctical data about the number of movies college students watch in a certain time frame. I have to find the average, median and mode and show this in the output. I am able to get my program to compile and run, but the output is not correct. Can anyone help with this please?

Here is the code:

#include <iostream>
#include <iomanip>
using namespace std;




int main()
{
    int *students; //dynamic allocator
    int stdSurveyed;  //amount of students surveyed, user input
    int total = 0;
    int *frequency;

  double  average = 0, median = 0, mode = 0;

  // USER INPUT
  cout << "How many students are being surveyed? ";
  cin >> stdSurveyed;


  students = new int[stdSurveyed]; //allocated memory.


  //EACH STUDENT INPUT
  cout << "How many movies did each student see? Enter below: " << endl;
  for (int count = 0; count < stdSurveyed; count++)
  {
  cout << "Student " << (count + 1) << ": ";
  cin >> students[count];
  }


  //AVERAGE
  for (int count = 0; count < stdSurveyed; count++)
  {
   total += students[count];
  }
  average = total / stdSurveyed;
  cout << "The average is: " << average << endl;


  //MEDIAN
    if (total % 2 == 0)
    {
    median = ((students[total/2-1])+(students[total/2])/2.0);
    }
    else if (total % 2 == 1)
    {
    median = students[total/2];
    }
    cout<< "The median is: " << median << endl;

  //MODE
    int x;
    int freq = 0;

    frequency = new int[freq];

    for (int count = 0; count < stdSurveyed; count++)
    {
    x=students[total];
    frequency[x]++;
    }
    cout << "The mode is: " << mode << endl;


  delete [] students;
  students = 0;



  system ("pause");
  return 0;

} 

And here is what the output looks like:

How many students are being surveyed? 5
How many movies did each student see? Enter below:
Student 1: 1
Student 2: 2
Student 3: 2
Student 4: 2
Student 5: 3
The average is: 2
The median is: 3
The mode is: 0
Press any key to continue . . .

Edited 3 Years Ago by Nick Evan: Fixed formatting

>>can't figure out what I'm doing wrong
That doesn't surprise me since you can't even figure out where to post this question.

Comments
ha ha ha - his first and last post I take it.

Posted in wrong section, missing code tags(rules violation), you forgot to delete a pointer, system() has no place in your code, you should branch your algorithms off into functions, and you shouldn't have declarations in the middle of your code.

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