Getting my pointer to send variable not address

So with this program as far as I know everything is set up properly except when it's suppose to tell me the total amount of movies that had been watched and the median it instead tells me the address of the number instead, of the number itself, any advice?

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

// Function Prototypes
void movieAvg(int *, int); // Function used for calculating the Average
void movieMed(int *, int); // Function used for calculating the Median

int main()
{
int *studentsPtr, // Used to dynamically allocate an array
stuSurvey, // Used to hold the cin value presented by the user
students; // Used to hold the value of the Ptr

// Getting the total amount of students of took part in this survey
cout << " How many students took part in this survey: ";
cin >> stuSurvey;

// Used to dynamically allocate an array that will be large enough for the
// total number of students involved
studentsPtr = new int[stuSurvey];

// Getting the total amount of movies each student watched.
cout << "Please enter the amount of movies each student watched. \n";
for (int count = 0; count < stuSurvey; count++)
{
cout << "Student #" << (count + 1) << ": ";
cin >> studentsPtr[count];
}

movieAvg(&students, stuSurvey);
movieMed(&students, stuSurvey);

// Used to free dynamically allocated memory
delete[] studentsPtr;
studentsPtr = 0;
return 0;
}

// Used to calculate the total number of movies that all the students watched.
void movieAvg(int *studentsPtr, int stuSurvey)
{
double total = 0.0,
average = 0.0;
for (int count = 0; count < stuSurvey; count++)
{
total += studentsPtr[count];
}
average = total / stuSurvey;
cout << "\nIn total, " << stuSurvey << " college students watched an average of ";
cout << average << " movies a month.\n";
}

// Used to sort and then calculate the median
void movieMed(int *studentsPtr, int stuSurvey)
{
int startCount,
minIndex,
minValue;
for (startCount = 0; startCount < (stuSurvey - 1); startCount++)
{
minIndex = startCount;
minValue = studentsPtr[startCount];
for (int index = (startCount + 1); index < stuSurvey; index++)
{
if (studentsPtr[index] < minValue)
{
minValue = studentsPtr[index];
minIndex = index;
}
}
studentsPtr[minIndex] = studentsPtr[startCount];
studentsPtr[startCount] = minValue;
}
int first = 0,
middle,
last = stuSurvey,
leftMiddle,
rightMiddle;
double middle2;
if (stuSurvey % 2 == 0) // In case the total number of students entered is even
{
leftMiddle = ((first + last) / 2) - 1;
rightMiddle = (first + last) / 2;
middle2 = (studentsPtr[leftMiddle] + studentsPtr[rightMiddle]) / 2;
cout << fixed << showpoint << setprecision(2);
cout << "The median value of the movies seen is: " << middle2 << "\n";
}
else
{
middle = (first + last) / 2;
cout << "The median value of the movies seen is: " << studentsPtr[middle] << "\n";
}
}
Do you mean to send studentsPtr instead of &students here? So you know how many movies were entered into the array back in main?

1
2
movieAvg(&students, stuSurvey);
movieMed(&students, stuSurvey);



Please enter the amount of movies each student watched. 
Student #1: 2 
Student #2: 5 
Student #3: 7 
In total, 3 college students watched an average of 4.66667 movies a month. 
The median value of the movies seen is: 5
Last edited on
There we go, Thank you very much!
Topic archived. No new replies allowed.