My code compiles and everything, but it currently just crashes and doesn't return to the original function which contains the user menu for this project. This is very similar code to what I had used on my previous project to accomplish a similar task of reading a file with a variable name input. I can only use IO Stream and fstream to do all of this. Any help at all would be appreciated. Thank you!
void readCars(Cars carsArray[]) {
int index1;
char inputFile[100];
cout << "Input file name:" << endl;
cin >> inputFile;
ifstream input(inputFile);
if (input) {
while (!input.eof()) {
for (index1 = 0; index1 < 5; index1++) {
input >> carsArray[index1].year >> carsArray[index1].make
>> carsArray[index1].model >> carsArray[index1].model
>> carsArray[index1].price >> carsArray[index1].available;
}
}
} else {
cerr << "Input file cannot be opened" << endl;
return;
}
return;
}