0

Hi guys. This is my first post and I hope I can get some help. Thanks so much in advance for this. I have what I'm sure is simple but I'm missing something here. I have a file being read from (input.txt) which has no more than 50 grades w/ -1 being a Sentinel value to end the file when looped. I am trying to find a way to create a frequency array that tells me how many times a grade is used so that I can find the mode for it.

This is what I have so far but anytime I run it , the program crashes. I'm using VS2007 and it doesnt give any errors when compiling but crashes when I run it. Please help me out. Thanks!

```
// Analyze and Output Mean, Median, Mode of Grades from File
//************************************************************************
#include <iostream> // I/O functions
#include <iomanip> // I/O formatting functions
#include <string> // string class
#include <cstdlib> // abs(), rand(), atof(), etc.
#include <cmath> // exp(), pow(), trig functions, floor/ceiling, etc.
#include <fstream> // read to and from files
using namespace std;
void BubbleSort(int qAns[], int n);
const int MAX_SIZE_GRADE = 50; // Max number of grades.
const int MAX_SIZE_FREQ = 101; //Max for freq array
const int SENTINEL = -1; //Value to end loop when read
int main()
{
int i, freqArray[MAX_SIZE_FREQ], gradeArray[MAX_SIZE_GRADE], mode;
float mean, median;
ifstream inFile;
ofstream outFile;
inFile.open("input.txt");
outFile.open("output.txt");
//Initialize frequency array elements to 0
for(i=0; i<MAX_SIZE_FREQ; i++)
{
freqArray[i]=0;
}
i=0;
//Read input file and store into array
while(gradeArray[i] != SENTINEL)
{
inFile>>gradeArray[i];
freqArray[gradeArray[i]]++; //Creating frequency array
i++;
}
//Output what was read in file (for debugging)
i=0;
while(gradeArray[i] != SENTINEL)
{
cout<<gradeArray[i]<<", ";
i++;
}
return 0;
}
```