I am trying to create a function which will open a file, read the numbers in a file, place those numbers in an array, and then return those numbers. So far I have:
void getPrices()
{
const int SEAT_PRICES = 2;
double prices[SEAT_PRICES];
int count = 0;
ifstream inputFile;
inputFile.open("C:\\data\\SeatPrices.txt");
while (count < SEAT_PRICES && inputFile >> prices[count])
count++;
inputFile.close();
//This part is just something to display the numbers in the file.
cout << "The numbers are: ";
for (count = 0; count < SEAT_PRICES; count++)
cout << prices[count] << " ";
cout <<endl;
For example you can return container with values. Bonus: it is can hold arbitrary amount of element. Also it is good to make function to take filename as a parameter to allow code reuse: