Ok so I got this to compile but now all it prints out to the screen is the "*" in my createHistogram function why doesnt it print the mean,median and mode with a histogram of the data?

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
// global constant declaration
const int MAX_SIZE = 50;
const int NUM_RANGE = 25;
int getNumbers( ofstream&  report, int  numbers[], int size, int range);
//void printResults( float mean, float median, float mode );
void createFrequency(int scores [] , int size, int frequency[], int range);
void createHistogram(int frequency[], int range);
//float calcMean(ofstream& report, int numbers, int size );
float calcMean(ofstream& report, int numbers[], int size );
void sort(int list[], int last);
void bubbleUp(int list[], int current, int last);
float calcMedian(ofstream& report, int list[], int size);
float calcMode(ofstream& report, int freq[], int size);
void printResults(float mean, float median, float mode);
int main()
{
float mean = 0;
float median = 0;
float mode= 0;
int frequency[NUM_RANGE+1];
int numbers[ MAX_SIZE ], size;
int list[50];
int scores[50];
int last;
int current;
ifstream inFile;
ofstream report;
report.open("scores.txt");
if (!report)
        {
                 cerr <<"\aerror opening  output file\n";
                 exit(102);
        }

size= getNumbers(report,numbers,MAX_SIZE,NUM_RANGE);
mean = calcMean(report,numbers,size);
createFrequency(scores,size,frequency,NUM_RANGE);
createHistogram(frequency, NUM_RANGE);
sort ( list, size);
bubbleUp( list, current, last);
median = calcMedian(report, list, size);
mode= calcMode(report, frequency, NUM_RANGE+1);
printResults(mean, median, mode );
report.close();
system("Pause");
return 0;
}
//===============getNumbers========================
int getNumbers( ofstream&  report,int numbers[ ], int size ,int NUM_RANGE)
{
      ifstream inFile;
inFile.open( "scores.txt" );
          if ( !inFile )
             {
                cerr << "scores.txt cannot be opened" << endl;
                   exit( 100 );
             }
         
            ofstream OutFile;
            OutFile.open("Reordersheet.txt");
            if(!OutFile)
              {
                 cerr<<"\a Error opening Reordersheet\n";
                 system("Pause");
                 
                 exit(102);
              }//if open fails 
         
         
         
         int dataIn;
         int i = 0;
         while (i < size  && (inFile >> dataIn))
      
              if (dataIn >= 0 && dataIn <= NUM_RANGE)
                 numbers[i++] = dataIn;
            else
       cout << "Data point " << dataIn
            << " invalid. Ignored. \n";
// Test to see what stopped while
 if (i == size && (inFile>> dataIn))
    // More data in file
    cout << "\nToo much data. Process what read.\n";
 
         while ( ( size < MAX_SIZE ) && ( inFile >> numbers[ size ] ) )
          {
             ++size;
            }
                 inFile.close( );
                    
return i;
}//end of getData
//===================Mean=======================
// finds the average of the numbers
float calcMean(ofstream &report, int numbers[ ], int size)
{
    float total=0;
     float mean;
          for (int i=0;i<size;i++)
           total= total+ numbers[i ];
           mean=total/size;
         
return mean;
}//End of mean
//===============createFrequency========================
//Creates the frequency of scores
void createFrequency(int numbers [] , int size, int frequency[],int range)
{
                     for(int i = 0;i <range;i++)
                         frequency [i]=0;
                        for (int i = 0; i < size; i++)
                       frequency [numbers [i]]++;
                       return;
}//end createFrequency
//===================createHistogram=======================
//Creates Histogram of scores
void createHistogram(int frequency[], int range)
{
       for(int i = 0;i<=range;i++)
            {
              cout<<setw(3)<<i<<setw(3)<<frequency[i];
               for(int j = 1;j<=frequency[i];j++)
                    {
                        cout<<"*";
                        cout<<endl;
                     }
}
return;
}//end createHistogram
//==========================calcMode==============================
float calcMode(ofstream& report, int frequency[], int size)
{
     int largest=0, mode;
    for(int i = 0; i < size; i++)
    {
        if(frequency[i] > largest)
        {
             largest = frequency[i];
        }
    }
    for(int i = 0; i < size; i++)
    {
      if(frequency[i] == largest)
       {
        mode = i;
      
        }
    }
return mode;
}
//===================sort=======================
 

void sort(int list[],int last)
{
     for(int current=0; current< last; current++)
             bubbleUp(list, current, last);
        return;
}//sort
//===============bubbleUp===============================
void bubbleUp(int list[], int current, int last)
{
for( int walker = last; walker > current; walker--)
if(list[walker] < list[walker-1])
{
int temp = list[walker];
list[walker] = list[walker-1];
list[walker-1] = temp;
}
return;
}//bubble sort
//===================Median=======================
//find the median of scores
float calcMedian(ofstream& report, int list[], int size)
{
   double median;
    sort(list, size); // this will sort the list
    if (size%2 ==0)
          {
          median = ((list[(size/2)+1]) + (list[size/2]))/2;
          median = floor(median);
           }
         else
            {
               median = (float) (list[size/2]);
               median = ceil(median);
             }
return median;

}
//==============printResults==============
//prints out results
void printResults( float mean, float median, float mode)
{
     cout<<"The mean is"<<setw(4)<<mean<<endl;
     cout<<"The median is"<<setw(4)<<median<<endl;
     cout<<"The mode is"<<setw(4)<<mode<<endl;
return;
}

I had a midterm problem similar to this last year.

The question was

3) Write a function using the following structure and prototype.

struct stat
{
    float avg;
    float median;
    float *mode;
    int nModes;
};

stat *avgMedMode(int *,int);

The function takes in an integer array and the size of the array.
Then returns a pointer to a structure containing the average, median
and mode. I will input a small array to test this out so ask for
how many inputs to fill the array, then the values to place into the
array. Make sure you delete the dynamic array creation for the mode
when you exit the problem.

My solution (as a module of the entire midterm program) is as follows:

// Frank C. Jamison
// April 08, 2006
// CIS 17A - Section 43052
// Borland C++ Builder Enterprise Suite Version 6.0
// Purpose:  Midterm Examination Program 3
// Midterm Examination

#include <iostream>
using namespace std;

// Structure Declarations - Midterm Program 3
struct stats {
  float avg;
  float median;
  int  *mode;
  int   nmodes;
};

// Function Declarations - Midterm Program 3
stats *avgMedMode(int *, int);
int   *createArray(int);
void   displayStats(stats);
int    findHighFrequency(int*, int);
int    findNumModes(int *, int, int);
float  getArrayAverage(int *, int);
void   getArrayElements(int *, int);
float  getArrayMedian(int *, int);
int    getModeArray(int *, int, int *, int);
void   programHeader3();
void   sortArrayElements(int *, int);

// Function Declarations - Multiple Files
void clear();
bool validLoNum(int, int);
void wait();


//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3                                                *
//*****************************************************************************
void problem3() {

  // Variable Definition
  int numElements;

  // Display program header
  programHeader3();

  // Get and validate number of integers to calculate
  do {
    cout << "\n\tNumber of integers: ";
    cin  >> numElements;
  } while (!validLoNum(numElements, 1));

  // Create dynamic array to hold integers
  int *intArray = createArray(numElements);

  // Get integer array elements
  getArrayElements(intArray, numElements);

  // Dynamically allocate memory for stats structure and set structure
  // variables
  stats *arrayStats = avgMedMode(intArray, numElements);

  // Display Integer Array Statistics
  displayStats(*arrayStats);

  // Free dynamically allocated memory
  delete [] arrayStats->mode;
  delete [] intArray;
  delete arrayStats;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Create Structure and Set Variables           *
//*****************************************************************************
stats *avgMedMode(int *arrayPtr, int numElements) {

  // Variable Definition
  int highFrequency;

  // Dymanically create stats structure
  stats *statStruct = new stats;

  // Sort survey results in ascending order
  sortArrayElements(arrayPtr, numElements);

  // Find highest integer frequency
  highFrequency = findHighFrequency(arrayPtr, numElements);

  // Find the number of modes in the array
  statStruct->nmodes = findNumModes(arrayPtr, numElements, highFrequency);

  // Dynamically create new array to hold mode of integer array
  int *modeArray = createArray(statStruct->nmodes);

  // Add modes to mode array
  *modeArray = getModeArray(modeArray, highFrequency, arrayPtr, numElements);

  // Set structure pointer to mode array
  statStruct->mode = modeArray;

  // Find the median value of the integer array
  statStruct->median = getArrayMedian(arrayPtr, numElements);

  // Find the average value of the integer array
  statStruct->avg = getArrayAverage(arrayPtr, numElements);

  return statStruct;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Dynamically Allocate Memory for Integer      *
//           Array                                                            *
//*****************************************************************************
int *createArray(int numElements) {

  // Dynamically allocate memory for integer array
  int *array = new int[numElements];

  // Return pointer to dynamically allocated memory for integer array
  return array;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Display Integer Array Statistics             *
//*****************************************************************************
void displayStats(stats arrayStruct) {

  // Display program header
  programHeader3();

  // Display integer array statistics
  cout << "\n\tInteger Array Statistics\n";
  cout << "\n\tArray Average:   " << arrayStruct.avg << endl;
  cout << "\n\tArray Median:    " << arrayStruct.median << endl;
  
  // If the array mode is set to -1, report that there is no mode
  if (*arrayStruct.mode == -1)
    cout << "\n\tArray Mode:      None";

  // If the array mode is not set to -1, display the array mode
  else {
    cout << "\n\tArray Mode:      ";

    for (int i = 0; i < arrayStruct.nmodes; i++)
      cout << arrayStruct.mode[i] << " ";
  }

  // Wait for user to hit [Enter] to continue
  wait();
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Find Highest Integer Frequency               *
//*****************************************************************************
int findHighFrequency(int* arrayPtr, int numElements) {

  // Local Variable Definitions
  int currentHigh   = 1,
      frequency     = 1,
      highFrequency = 1;

  // Check the frequency of each element in the array
  for (int i=1; i < numElements; i++) {

    // If the current element has the same value as previous element,
    // add 1 to frequency
    if (arrayPtr[i] == arrayPtr[i - 1])
      frequency += 1;

    // If the current element has a different value than the previous,
    // set the value of currentHigh to frequency and reset frequency to 1
    else {
      currentHigh = frequency;
      frequency = 1;

      // If value of currentHigh is greater highFrequency, set value of
      // highFrequency to currentHigh
      if (currentHigh > highFrequency)
        highFrequency = currentHigh;
    }

    // If all elements in the array have the same value, set value of
    // highFrequency to frequency
    if (frequency > highFrequency)
      highFrequency = frequency;
  }

  // Return the highest integer frequency
  return highFrequency;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Find Number of Modes in Integer Array        *                                                           *
//*****************************************************************************
int findNumModes(int *arrayPtr, int numElements, int highFrequency) {

  // Variable Definitions
  int frequency = 1,
      numModes  = 0;

  // Check the frequency of each element in the array
  for (int i=1; i < numElements; i++) {

    // If the current element has same value as previous element,
    // add 1 to frequency
    if (arrayPtr[i] == arrayPtr[i-1]) {
      frequency += 1;

      // If frequency has the same value as highFrequency, add 1 to
      // numModes
      if (frequency == highFrequency)
        numModes += 1;
    }

    // If current element has a different value than the previous
    // element, reset frequency to 1
    else
      frequency = 1;
  }

  // If there is only one element in the array, set numModes to 1
  if (numModes == 0)
    numModes = 1;

  // Return the number of modes in the array
  return numModes;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Get the Average Value of the Integer Array   *                                                         *
//*****************************************************************************
float getArrayAverage(int *arrayPtr, int numElements) {

  // Local Variable Definitions
  float average = 0.0;

  // Get the sum of all array elements
  for (int i = 0; i < numElements; i++)
    average += arrayPtr[i];

  // Divide the sum of the array elements by the number of array elements
  average = average / numElements;

  // Return the average value of the integer array
  return average;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Get Elements for Integer Array Pointed To    *
//*****************************************************************************
void getArrayElements(int *arrayPtr, int numElememts) {

  // Display program header
  programHeader3();

  // Get and validate integer for each array element
  for (int i = 0; i < numElememts; i++) {

    do {
      cout << "\n\tEnter an integer for Element " << (i + 1) << ": ";
      cin  >> arrayPtr[i];
    } while (!validLoNum(arrayPtr[i], 0));
  }
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Get the Median Value of the Integer Array    *                                                        *
//*****************************************************************************
float getArrayMedian(int* arrayPtr, int numElements) {

  // Variable Definitions
  int   middle,
        midpoint1,
        midpoint2;
  float median;

  // If there are an even number of elements, calculate the average of
  // the two middle elements
  if (numElements %2 == 0) {
    midpoint1 = (numElements / 2);
    midpoint2 = midpoint1 - 1;
    median    = (arrayPtr[midpoint1] + arrayPtr[midpoint2]) / 2.0;
  }

  // If there is an odd number of elements, get the middle element
  else {
    middle = (numElements / 2);
    median = arrayPtr[middle];
  }

  // Return the median value
  return median;
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Get the Modes of the Integer Array           *
//*****************************************************************************
int getModeArray(int *modeArrayPtr, int highFrequency, int* arrayPtr,
                 int numElements) {

  // Variable Definitions
  int frequency   = 1,
      modeElement = 0;

  // If the integer array has no mode, return -1
  if (highFrequency == 1)
    return -1;

  // If the integer array has a mode, add mode values to the mode array
  else {

    // Get mode elements from the integer array
    for (int i=1; i < numElements; i++) {

      // If the value in the current array element is the same as the
      // previous element, add 1 to frequency
      if (arrayPtr[i] == arrayPtr[i-1]) {
        frequency += 1;

        // If the current frequency is the same as the high frequency,
        // add the value in the current element to the mode array
        if (frequency == highFrequency) {
          modeArrayPtr[modeElement] = arrayPtr[i];
          modeElement += 1;
        }
      }

      // If the value in the current array element is not the same as
      // the previous element, reset the frequency counter to 1
      else
        frequency = 1;
    }

    // Return the mode array
    return *modeArrayPtr;
  }
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Display Program Header                       *
//*****************************************************************************
void programHeader3() {

  // Clear the screen
  system("cls");

  // Display the program screen header
  cout << "\n\n\tMIDTERM PROGRAM 3 - Average, Median, and Mode\n\n";
}

//*****************************************************************************
// FUNCTION: MIDTERM PROBLEM 3 - Sort Elements of Integer Array Pointed To in *
//           Ascending Order                                                  *
//*****************************************************************************
void sortArrayElements(int *arrayPtr, int numElememts) {

  // Local Variable Definitions
  int minIndex,
      minValue,
      startScan;

  // Sort array elements in ascending order
  for (startScan = 0; startScan < (numElememts - 1); startScan++) {

    // Initialize variables
    minIndex = startScan;
    minValue = arrayPtr[startScan];

    // Check next element in the array for a smaller number
    for (int index = (startScan + 1); index < numElememts; index++) {

      // If the next element is smaller, store its value and index
      // number in minValue and minIndex variables
      if (arrayPtr[index] < minValue) {
        minValue = arrayPtr[index];
        minIndex = index;
      }
    }

    // Copy current element to next element and replace current element
    // with stored smaller value
    arrayPtr[minIndex]  = arrayPtr[startScan];
    arrayPtr[startScan] = minValue;
  }
}
ifstream inFile;
ofstream report;
report.open("scores.txt");
if (!report)
{
	cerr <<"\aerror opening  output file\n";
	exit(102);
}
size= getNumbers(report,numbers,MAX_SIZE,NUM_RANGE);

<snip>

int getNumbers( ofstream&  report,int numbers[ ], int size ,int NUM_RANGE)
{
      ifstream inFile;
	inFile.open( "scores.txt" );

why do you open scores.txt for output in main then expect to read anything from that file in getNumbers()? When you open the file for output in main() all data in the file is lost. So getNumbers() will not really do anything.

Ok so i put the ofstream insided get numbers and put a system pause there so i can see what its printing and it it just prints the histogram but its not reading the data I think because it just prints this: 0 0
1 0
all the way to 25 then just "*" So how do i fix this so it prints all the times the number showed up then the mean median and mode? I got it to show me that mean is -1 #INDV I dont know what that means

repost your code and also attach the data file.

Ok I got rid of the ofstream because I didnt think i needed it becuase i just want to write this to the screen not another file. So i changed all the ofstream reports ifstream inFile but now it wont compile like it did before it says there is a linker error. But if i leave the ofstream report in getNumbers before the ifstream inFile it will compile but just give me the histogram like before like it hadnt got the data.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
// global constant declaration
const int MAX_SIZE = 50;
const int NUM_RANGE = 25;
int getNumbers( ifstream&  inFile, int  numbers[], int size, int range);
//void printResults( float mean, float median, float mode );
void createFrequency(int scores [] , int size, int frequency[], int range);
void createHistogram(int frequency[], int range);
//float calcMean(ofstream& report, int numbers, int size );
float calcMean(ifstream& inFile, int numbers[], int size );
void sort(int list[], int last);
void bubbleUp(int list[], int current, int last);
float calcMedian(ifstream& inFile, int list[], int size);
float calcMode(ifstream& inFile, int freq[], int size);
void printResults(float mean, float median, float mode);
int main()
{
float mean = 0;
float median = 0;
float mode= 0;
int frequency[NUM_RANGE+1];
int numbers[ MAX_SIZE ], size;
int list[50];
int scores[50];
int last;
int current;
ifstream inFile;
 
size= getNumbers(inFile,numbers,MAX_SIZE,NUM_RANGE);
mean = calcMean(inFile,numbers,size);
createFrequency(scores,size,frequency,NUM_RANGE);
createHistogram(frequency, NUM_RANGE);
sort ( list, size);
bubbleUp( list, current, last);
median = calcMedian(inFile, list, size);
mode= calcMode(inFile, frequency, NUM_RANGE+1);
printResults(mean, median, mode );
system("Pause");
return 0;
}
//===============getNumbers========================
int getNumbers( ofstream&  report,int numbers[ ], int size ,int NUM_RANGE)
{
 
 
 
 
 
 
      ifstream inFile;
      inFile.open( "scores.txt" );
          if ( !inFile )
             {
                cerr << "scores.txt cannot be opened" << endl;
                   exit( 100 );
             }
 
 
 
 
 
         int dataIn;
         int i = 0;
         while (i < size  && (inFile >> dataIn))
 
              if (dataIn >= 0 && dataIn <= NUM_RANGE)
                 numbers[i++] = dataIn;
            else
       cout << "Data point " << dataIn
            << " invalid. Ignored. \n";
// Test to see what stopped while
 if (i == size && (inFile>> dataIn))
    // More data in file
    cout << "\nToo much data. Process what read.\n";
 
         while ( ( size < MAX_SIZE ) && ( inFile >> numbers[ size ] ) )
          {
             ++size;
            }
 
                 report.close(); 
return i;
}//end of getData
//===================Mean=======================
// finds the average of the numbers
float calcMean(ofstream &report, int numbers[ ], int size)
{
    float total=0;
     float mean;
          for (int i=0;i<size;i++)
           total= total+ numbers[i ];
           mean=total/size;
 
return mean;
}//End of mean
//===============createFrequency========================
//Creates the frequency of scores
void createFrequency(int numbers [] , int size, int frequency[],int range)
{
                     for(int i = 0;i <range;i++)
                         frequency [i]=0;
                        for (int i = 0; i < size; i++)
                       frequency [numbers [i]]++;
                       return;
}//end createFrequency
//===================createHistogram=======================
//Creates Histogram of scores
void createHistogram(int frequency[], int range)
{
       for(int i = 0;i<=range;i++)
            {
              cout<<setw(3)<<i<<setw(3)<<frequency[i];
               for(int j = 1;j<=frequency[i];j++)
                    {
                        cout<<"*";
                        cout<<endl;
                     }
system("Pause");
}
return;
}//end createHistogram
//==========================calcMode==============================
float calcMode(ofstream& report, int frequency[], int size)
{
     int largest=0, mode;
    for(int i = 0; i < size; i++)
    {
        if(frequency[i] > largest)
        {
             largest = frequency[i];
        }
    }
    for(int i = 0; i < size; i++)
    {
      if(frequency[i] == largest)
       {
        mode = i;
 
        }
    }
return mode;
}
//===================sort=======================
 
void sort(int list[],int last)
{
     for(int current=0; current< last; current++)
             bubbleUp(list, current, last);
        return;
}//sort
//===============bubbleUp===============================
void bubbleUp(int list[], int current, int last)
{
for( int walker = last; walker > current; walker--)
if(list[walker] < list[walker-1])
{
int temp = list[walker];
list[walker] = list[walker-1];
list[walker-1] = temp;
}
return;
}//bubble sort
//===================Median=======================
//find the median of scores
float calcMedian(ofstream& report, int list[], int size)
{
   double median;
    sort(list, size); // this will sort the list
    if (size%2 ==0)
          {
          median = ((list[(size/2)+1]) + (list[size/2]))/2;
          median = floor(median);
           }
         else
            {
               median = (float) (list[size/2]);
               median = ceil(median);
             }
return median;
}
//==============printResults==============
//prints out results
void printResults( float mean, float median, float mode)
{
     cout<<"The mean is"<<setw(4)<<mean<<endl;
     cout<<"The median is"<<setw(4)<<median<<endl;
     cout<<"The mode is"<<setw(4)<<mode<<endl;
return;
}
float calcMode(ifstream& inFile, int freq[], int size);

...
...
float calcMode(ofstream& report, int frequency[], int size)
{

Those are not the same functions. The parameter types must be identical in the prototype and the actual function.

I know i had them all changed to inFile instead of report and got rid of the ofstream. but then it wouldnt compile it comes up with a linker error

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
// global constant declaration
const int MAX_SIZE = 50;
const int NUM_RANGE = 25;
int getNumbers( ifstream& inFile, int numbers[], int size, int range);
//void printResults( float mean, float median, float mode );
void createFrequency(int scores [] , int size, int frequency[], int range);
void createHistogram(int frequency[], int range);
//float calcMean(ofstream& report, int numbers, int size );
float calcMean(ifstream& inFile, int numbers[], int size );
void sort(int list[], int last);
void bubbleUp(int list[], int current, int last);
float calcMedian(ifstream& inFile, int list[], int size);
float calcMode(ifstream& inFile, int freq[], int size);
void printResults(float mean, float median, float mode);
int main()
{
float mean = 0;
float median = 0;
float mode= 0;
int frequency[NUM_RANGE+1];
int numbers[ MAX_SIZE ], size;
int list[50];
int scores[50];
int last;
int current;
ifstream inFile;
 
size= getNumbers(inFile,numbers,MAX_SIZE,NUM_RANGE);
mean = calcMean(inFile,numbers,size);
createFrequency(scores,size,frequency,NUM_RANGE);
createHistogram(frequency, NUM_RANGE);
sort ( list, size);
bubbleUp( list, current, last);
median = calcMedian(inFile, list, size);
mode= calcMode(inFile, frequency, NUM_RANGE+1);
printResults(mean, median, mode );
system("Pause");
return 0;
}
//===============getNumbers========================
int getNumbers( ifstream& inFile,int numbers[ ], int size ,int NUM_RANGE)
{
 
 
 
 
 
 
 
inFile.open( "scores.txt" );
if ( !inFile )
{
cerr << "scores.txt cannot be opened" << endl;
exit( 100 );
}
 
 
 
 
int dataIn;
int i = 0;
while (i < size && (inFile >> dataIn))
 
if (dataIn >= 0 && dataIn <= NUM_RANGE)
numbers[i++] = dataIn;
else
cout << "Data point " << dataIn
<< " invalid. Ignored. \n";
// Test to see what stopped while
if (i == size && (inFile>> dataIn))
// More data in file
cout << "\nToo much data. Process what read.\n";
 
while ( ( size < MAX_SIZE ) && ( inFile >> numbers[ size ] ) )
{
++size;
}
 
inFile.close(); 
return i;
}//end of getData
//===================Mean=======================
// finds the average of the numbers
float calcMean(ofstream &report, int numbers[ ], int size)
{
float total=0;
float mean;
for (int i=0;i<size;i++)
total= total+ numbers[i ];
mean=total/size;
 
return mean;
}//End of mean
//===============createFrequency========================
//Creates the frequency of scores
void createFrequency(int numbers [] , int size, int frequency[],int range)
{
for(int i = 0;i <range;i++)
frequency [i]=0;
for (int i = 0; i < size; i++)
frequency [numbers [i]]++;
return;
}//end createFrequency
//===================createHistogram=======================
//Creates Histogram of scores
void createHistogram(int frequency[], int range)
{
for(int i = 0;i<=range;i++)
{
cout<<setw(3)<<i<<setw(3)<<frequency[i];
for(int j = 1;j<=frequency[i];j++)
{
cout<<"*";
cout<<endl;
}
system("Pause");
}
return;
}//end createHistogram
//==========================calcMode==============================
float calcMode(ofstream& report, int frequency[], int size)
{
int largest=0, mode;
for(int i = 0; i < size; i++)
{
if(frequency[i] > largest)
{
largest = frequency[i];
}
}
for(int i = 0; i < size; i++)
{
if(frequency[i] == largest)
{
mode = i;
 
}
}
return mode;
}
//===================sort=======================
 
void sort(int list[],int last)
{
for(int current=0; current< last; current++)
bubbleUp(list, current, last);
return;
}//sort
//===============bubbleUp===============================
void bubbleUp(int list[], int current, int last)
{
for( int walker = last; walker > current; walker--)
if(list[walker] < list[walker-1])
{
int temp = list[walker];
list[walker] = list[walker-1];
list[walker-1] = temp;
}
return;
}//bubble sort
//===================Median=======================
//find the median of scores
float calcMedian(ofstream& report, int list[], int size)
{
double median;
sort(list, size); // this will sort the list
if (size%2 ==0)
{
median = ((list[(size/2)+1]) + (list[size/2]))/2;
median = floor(median);
}
else
{
median = (float) (list[size/2]);
median = ceil(median);
}
return median;
}
//==============printResults==============
//prints out results
void printResults( float mean, float median, float mode)
{
cout<<"The mean is"<<setw(4)<<mean<<endl;
cout<<"The median is"<<setw(4)<<median<<endl;
cout<<"The mode is"<<setw(4)<<mode<<endl;
return;
}
float calcMode(ifstream& inFile, int freq[], int size);

...
...
float calcMode(ofstream& report, int frequency[], int size)
{

You still haven't updated your function to match your prototype. That's why you're getting that linker error.

Ok I thought i sent this one last night but guess not. I got it all to compile but when i go to run it it comes up with an error message from my computer not one that was in my program. I have never seen this before.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
// global constant declaration
const int MAX_SIZE = 50;
const int NUM_RANGE = 25;
int getNumbers( ifstream&  inFile, int  numbers[], int size, int range);
//void printResults( float mean, float median, float mode );
void createFrequency(int scores [] , int size, int frequency[], int range);
void createHistogram(int frequency[], int range);
//float calcMean(ofstream& report, int numbers, int size );
float calcMean(ifstream& inFile, int numbers[], int size );
void sort(int list[], int last);
void bubbleUp(int list[], int current, int last);
float calcMedian(ifstream& inFile, int list[], int size);
float calcMode(ifstream& inFile, int freq[], int size);
void printResults(float mean, float median, float mode);
int main()
{
float mean = 0;
float median = 0;
float mode= 0;
int frequency[NUM_RANGE+1];
int numbers[ MAX_SIZE ], size;
int list[50];
int scores[50];
int last;
int current;
ifstream inFile;
 
size= getNumbers(inFile,numbers,MAX_SIZE,NUM_RANGE);
mean = calcMean(inFile,numbers,size);
createFrequency(scores,size,frequency,NUM_RANGE);
createHistogram(frequency, NUM_RANGE);
sort ( list, size);
bubbleUp( list, current, last);
median = calcMedian(inFile, list, size);
mode= calcMode(inFile, frequency, NUM_RANGE+1);
printResults(mean, median, mode );
system("Pause");
return 0;
}
//===============getNumbers========================
int getNumbers( ifstream&  inFile,int numbers[ ], int size ,int NUM_RANGE)
{
     
   
      
          inFile.open( "scores.txt" );
          if ( !inFile )
             {
                cerr << "scores.txt cannot be opened" << endl;
                   exit( 100 );
             }
         
         
         
         
         int dataIn;
         int i = 0;
         while (i < size  && (inFile >> dataIn))
      
              if (dataIn >= 0 && dataIn <= NUM_RANGE)
                 numbers[i++] = dataIn;
            else
       cout << "Data point " << dataIn
            << " invalid. Ignored. \n";
// Test to see what stopped while
 if (i == size && (inFile>> dataIn))
    // More data in file
    cout << "\nToo much data. Process what read.\n";
 
         while ( ( size < MAX_SIZE ) && ( inFile >> numbers[ size ] ) )
          {
             ++size;
            }
                 
                 inFile.close(); 
return i;
}//end of getData
//===================Mean=======================
// finds the average of the numbers
float calcMean(ifstream& inFile, int numbers[ ], int size)
{
    float total=0;
     float mean;
          for (int i=0;i<size;i++)
           total= total+ numbers[i ];
           mean=total/size;
         
return mean;
}//End of mean
//===============createFrequency========================
//Creates the frequency of scores
void createFrequency(int numbers [] , int size, int frequency[],int range)
{
                     for(int i = 0;i <range;i++)
                         frequency [i]=0;
                        for (int i = 0; i < size; i++)
                       frequency [numbers [i]]++;
                       return;
}//end createFrequency
//===================createHistogram=======================
//Creates Histogram of scores
void createHistogram(int frequency[], int range)
{
       for(int i = 0;i<=range;i++)
            {
              cout<<setw(3)<<i<<setw(3)<<frequency[i];
               for(int j = 1;j<=frequency[i];j++)
                    {
                        cout<<"*";
                        cout<<endl;
                     }
system("Pause");
}
return;
}//end createHistogram
//==========================calcMode==============================
float calcMode(ifstream& inFile, int frequency[], int size)
{
     int largest=0, mode;
    for(int i = 0; i < size; i++)
    {
        if(frequency[i] > largest)
        {
             largest = frequency[i];
        }
    }
    for(int i = 0; i < size; i++)
    {
      if(frequency[i] == largest)
       {
        mode = i;
      
        }
    }
return mode;
}
//===================sort=======================
 
void sort(int list[],int last)
{
     for(int current=0; current< last; current++)
             bubbleUp(list, current, last);
        return;
}//sort
//===============bubbleUp===============================
void bubbleUp(int list[], int current, int last)
{
for( int walker = last; walker > current; walker--)
if(list[walker] < list[walker-1])
{
int temp = list[walker];
list[walker] = list[walker-1];
list[walker-1] = temp;
}
return;
}//bubble sort
//===================Median=======================
//find the median of scores
float calcMedian(ifstream& inFile, int list[], int size)
{
   double median;
    sort(list, size); // this will sort the list
    if (size%2 ==0)
          {
          median = ((list[(size/2)+1]) + (list[size/2]))/2;
          median = floor(median);
           }
         else
            {
               median = (float) (list[size/2]);
               median = ceil(median);
             }
return median;
}
//==============printResults==============
//prints out results
void printResults( float mean, float median, float mode)
{
     cout<<"The mean is"<<setw(4)<<mean<<endl;
     cout<<"The median is"<<setw(4)<<median<<endl;
     cout<<"The mode is"<<setw(4)<<mode<<endl;
return;
}

you're calling createFrequency(scores,size,frequency,NUM_RANGE); in main, but scores[] doesn't have values yet, so when it it used here:

void createFrequency(int numbers [] , int size, int frequency[],int range)
{
    for(int i = 0;i <range;i++)
       frequency [i]=0;
    for (int i = 0; i < size; i++)
       frequency [numbers [i]] = frequency [numbers [i]] + 1;
    return;
}//end createFrequency

you're using random-memory adressess: Crash

So i do i need to call my create frequency later of change something else.

So i do i need to call my create frequency later of change something else.

I'm not sure, you're not using scores[] in the rest of your program, so what's the point of the array, what's it purpose?
If you just give it an initial value you wouldn't get the error but I think your program won't give the output you expect.
You could use a loop or memcpy for this.

Ok I got rid of scores it was supposed to be numbers not scores. so now it runs but when it gets past the 25 line it just shows ***** all the way down with showing my mean median and mode and any ideas why it doesnt break out of the histogram loop then go to the other functions.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
// global constant declaration
const int MAX_SIZE = 50;
const int NUM_RANGE = 25;
int getNumbers( ifstream&  inFile, int  numbers[], int size, int range);
//void printResults( float mean, float median, float mode );
void createFrequency(int numbers[], int size, int frequency[], int range);
void createHistogram(int frequency[], int range);
//float calcMean(ofstream& report, int numbers, int size );
float calcMean(ifstream& inFile, int numbers[], int size );
void sort(int numbers[], int last);
void bubbleUp(int numbers[], int current, int last);
float calcMedian(ifstream& inFile, int numbers[], int size);
float calcMode(ifstream& inFile, int freq[], int size);
void printResults(float mean, float median, float mode);
int main()
{
float mean = 0;
float median = 0;
float mode= 0;
int frequency[NUM_RANGE+1];
int numbers[ MAX_SIZE ], size;
int list[50];
int last;
int current;
ifstream inFile;
 
size= getNumbers(inFile,numbers,MAX_SIZE,NUM_RANGE);
mean = calcMean(inFile,numbers,size);
createFrequency(numbers,size,frequency,NUM_RANGE);
createHistogram(frequency, NUM_RANGE);
sort ( numbers, size);
bubbleUp( numbers, current, last);
median = calcMedian(inFile, list, size);
mode= calcMode(inFile, frequency, NUM_RANGE+1);
printResults(mean, median, mode );
system("Pause");
return 0;
}
//===============getNumbers========================
int getNumbers( ifstream&  inFile,int numbers[ ], int size ,int NUM_RANGE)
{
     
   
      
          inFile.open( "scores.txt" );
          if ( !inFile )
             {
                cerr << "scores.txt cannot be opened" << endl;
                   exit( 100 );
             }
         
         
         
         
         int dataIn;
         int i = 0;
         while (i < size  && (inFile >> dataIn))
      
              if (dataIn >= 0 && dataIn <= NUM_RANGE)
                 numbers[i++] = dataIn;
            else
       cout << "Data point " << dataIn
            << " invalid. Ignored. \n";
// Test to see what stopped while
 if (i == size && (inFile>> dataIn))
    // More data in file
    cout << "\nToo much data. Process what read.\n";
 
         while ( ( size < MAX_SIZE ) && ( inFile >> numbers[ size ] ) )
          {
             ++size;
            }
                 
                 inFile.close(); 
return i;
}//end of getData
//===================Mean=======================
// finds the average of the numbers
float calcMean(ifstream& inFile, int numbers[ ], int size)
{
    float total=0;
     float mean;
          for (int i=0;i<size;i++)
           total= total+ numbers[i ];
           mean=total/size;
         
return mean;
}//End of mean
//===============createFrequency========================
//Creates the frequency of scores
void createFrequency(int numbers [] , int size, int frequency[],int range)
{
                     for(int i = 0;i <range;i++)
                         frequency [i]=0;
                        for (int i = 0; i < size; i++)
                       frequency [numbers [i]]++;
                       return;
}//end createFrequency
//===================createHistogram=======================
//Creates Histogram of scores
void createHistogram(int frequency[], int range)
{
       for(int i = 0;i<=range;i++)
            {
              cout<<setw(3)<<i<<setw(3)<<frequency[i];
               for(int j = 1;j<=frequency[i];j++)
                   {
                        cout<<"*";
                      
                    }
  system("Pause");                      
}
return;
}//end createHistogram
//==========================calcMode==============================
float calcMode(ifstream& inFile, int frequency[], int size)
{
     int largest=0, mode;
    for(int i = 0; i < size; i++)
    {
        if(frequency[i] > largest)
        {
             largest = frequency[i];
        }
    }
    for(int i = 0; i < size; i++)
    {
      if(frequency[i] == largest)
       {
        mode = i;
      
        }
    }
return mode;
}
//===================sort=======================
 
void sort(int numbers[],int last)
{
     for(int current=0; current< last; current++)
             bubbleUp(numbers, current, last);
        return;
}//sort
//===============bubbleUp===============================
void bubbleUp(int numbers[], int current, int last)
{
for( int walker = last; walker > current; walker--)
if(numbers[walker] < numbers[walker-1])
{
int temp = numbers[walker];
numbers[walker] = numbers[walker-1];
numbers[walker-1] = temp;
}
return;
}//bubble sort
//===================Median=======================
//find the median of scores
float calcMedian(ifstream& inFile, int numbers[], int size)
{
   double median;
    sort(numbers, size); // this will sort the list
    if (size%2 ==0)
          {
          median = ((numbers[(size/2)+1]) + (numbers[size/2]))/2;
          median = floor(median);
           }
         else
            {
               median = (float) (numbers[size/2]);
               median = ceil(median);
             }
return median;
}
//==============printResults==============
//prints out results
void printResults( float mean, float median, float mode)
{
     cout<<"The mean is"<<setw(4)<<mean<<endl;
     cout<<"The median is"<<setw(4)<<median<<endl;
     cout<<"The mode is"<<setw(4)<<mode<<endl;
return;
}

You declare frequency being the size of NUM_RANGE+1, yet you only pass NUM_RANGE as the range value for createFrequency(). This causes the loop which initalizes the variables to only initalize the first 24 elements, leaving the 25th at some random value. Try adding NUM_RANGE+1 when you call createFrequency().

Why are you using ifstream as a parameter for calculateMedian()? You're not using it, and you shouldn't be. There is NO need for it. And you're not passing number to calculateMedian() in main(). Instead, you're passing an unitialized array filled with junk. No wonder it comes up with some weird results. So, what you need to do is remove the ifstream parameter, and add a parameter for the list, so you end up passing to calculateMean:

number[], list[], and size

That's it.

Alright got it up and going. Thank you very much to everyone who helped me figure this out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.