When running my C++ program with xCode, it is facing a SIGABRT error every time the program is run. The program runs fine, it just outputs this error at the very end of execution.
I have tried commenting out different parts of my different functions, looked in the debugger at all the variable values, and everything seems to check out, I just can't figure out why my program crashes at the very end.
Here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
int output(int, int[]);
void input(int, int[], int&, int&, int&, int&, double&, int );
void display(int, int, int , int , double);
using namespace std;
int main()
{
int const SIZE = 5000;
int numArray[SIZE] = {0};
int lowest, highest;
int total =0;
double average = 0;
int count = 0;
int fileSize = output(SIZE, numArray);
input(SIZE, numArray, lowest, highest, total, count, average, fileSize);
display(count, lowest, highest, total, average);
return 0;
}
int output(int SIZE, int numArray[])
{
ofstream outputFile;
int random;
unsigned seed = time(0);
srand(seed);
int const MIN = 4000;
int const MAX = 5000;
outputFile.open("numbers.txt");
int fileSize = (rand() % (MAX - MIN + 1) + MIN);
cout << fileSize << endl;
for (int x = 0; x < fileSize ; x++)
{
random = (rand() % (MAX - MIN + 1) + MIN);
outputFile << random << endl;
numArray[x] = random;
}
for (int x = 5000; x >= fileSize ; x--)
{
numArray[x] = 0;
}
outputFile.close();
return (fileSize);
}
void input(int SIZE, int numArray[], int& lowest, int& highest, int& total, int& count, double& average, int fileSize)
{
string fileName;
ifstream inputFile;
cout << "Enter the file name: ";
getline (cin, fileName);
inputFile.open(fileName);
lowest = numArray[0];
highest = numArray[0];
for (int i = 0; i < fileSize; i++)
{
count = i+1;
total += numArray[i];
average = static_cast<double> (total)/fileSize;
cout << numArray[i] << endl;
if (numArray[i] < lowest)
lowest = numArray[i];
if (numArray[i] > highest)
highest = numArray[i];
}
inputFile.close();
}
void display(int count, int lowest, int highest, int total, double average)
{
cout << "The total count of numbers in the Array: " << count <<endl;
cout << "The lowest number in the array: " << lowest << endl;
cout << "The highest number in the array: " << highest << endl;
cout << "The total of the numbers in the array: " << total << endl;
cout << "The average of the numbers in the array: " << average << endl;
return;
}