for (i = 0; i < arraySize; i++)
{
cout << "Score " << (i + 1) << ": " << movieArray[i+1] << endl;
}
}
void averageScore(double *movieArray, int arraySize)
{
double storage = 0, average;
int i;
for (i = 0; i < arraySize; i++)
{
//cout << "debug a" << endl;
storage = storage + movieArray[i+1];
}
//cout << "debug b" << endl;
average = storage / arraySize;
cout << "\nThe average number of movies seen is: " << average << endl;
}
void findMode (double *movieArray, int arraySize)
{
int count = 0, countTemp = 0; // initialize the mode counter to contain all zeroes
int largestCount = 0, mode = 0;
int i, j;
cout << "debug a" << endl;
for (i = 0; i < arraySize - 1; i++)
{ cout << "debug i" << endl;
for (j = i+1; j < arraySize; j++)
{ cout << "debug j" << endl;
if (movieArray[i] == movieArray[j])
{
countTemp++; // increment corresponding count
//cout << count[i] << endl;
}
if ( largestCount < countTemp)
{
largestCount = countTemp;
mode = i;
}
countTemp = 0;
}
}
cout << "Exit from the loop" << endl;
// mode = movieArray[0];
// largestCount = count[0]; // find largest count, and hence the mode
//for (i = 0; i < arraySize; i++)
//{
// //if (count[i] > largestCount)
// //{
// // largestCount = count[i];
// // mode = movieArray[i];
// //}
//}
cout << "The Mode is: " << movieArray[mode] << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
double *movie, average;
int numStudents, count;
cout << "How man students were surveyed?: ";
cin >> numStudents;
movie = new double[numStudents];
cout << "How many movies did this student watch?:" << endl;
for (count = 0; count < numStudents; count++)
{
cout << "Student " << (count + 1) << ": ";
cin >> movie[count];
if (movie[count] < 0)
{
movie[count] *= -1;
}
}
Firstly, let's take a look at a simple test case. Take 1 student through your sort routine. The array element movieArray[i+1] is probably not what you're looking for, as that array element does not exist.