I am having trouble returning my two arrays that I dynamically allocate. I have an external file reading the size of the array. (20 in my case) and that is making the array size when I use the dynamically allocated arrays.
Also once I return them, is my current syntax correct or is there something that I should change.
Here is my code
int main (void)
{
int size;
int notFound = 0;
int accountNumber = 0;
int results;
int * accountPtr = nullptr;
double * balancePtr = nullptr;
size = readFile(notFound, accountPtr, balancePtr);
if (notFound == 0)
{
selectionSort(accountPtr, balancePtr, size);
while (accountNumber != -99)
{
cout << "Please Enter an Account Number (Type -99 to quit): ";
cin >> accountNumber;
if (accountNumber == -99)
{
cout << "Goodbye!" << endl;
}
else
{
results = binarySearch(accountPtr,accountNumber,size);
if ( results == -1)
{
cout << "That Account Number Does Not Exist." << endl;
}
else
{
cout << "\nAccount Number" << "\t\t" << "Account Balance" << endl;
cout << "-----------------------------------------------" << endl;
cout << fixed << setprecision(2) << accountPtr[results] << "\t\t\t" << balancePtr[results] << endl << endl;
}
}
}
}
return 0;
}
int readFile (int ¬Found, int *accountPtr, double *balancePtr)
{
int size;
ifstream inputFile;
inputFile.open("account.txt");
if (inputFile.fail())
{
cout << "The File Account.TXT was not found." << endl;
notFound = 1;
}
else
{
inputFile >> size;
unique_ptr<int[]> accountPtr(new int[size]);
unique_ptr<double[]> balancePtr(new double[size]);
for(int i = 0; i < size; i++)
{
inputFile >> accountPtr[i] >> balancePtr[i];
}
}
return size;
}