This is for homework
So I don't think I need to go into the specifics about my project but the issue with my program is that for my case 1, I need the program to just read a file and store the contents of that file in an array of structs. So here's my program and I'll go into further detail below
#include <iostream>
#include<fstream>
using namespace std;
char filea[10]; //Global variables going to be used for the input file
struct cars{ //Like the movie
int year;
char make[10];
char model[10];
float price;
bool ava;
};
void record(cars cars2[]);
int main(void) {
int option = 0;
cars cars2[10]; //Like the movie -> cars2 will be used for the functions
do {
cout << endl; //Extra space to make it look organized
cout << "1. Record the File" << endl;
cout << "2. Show Car Information" << endl;
cout << "3. Transfer Information into Another File" << endl;
cout << "4. List the Cars Based on Price(Low-High)" << endl;
cout << "5. Total Price After Entering Days" << endl;
cout << "6. Choice of Car(enter index) and Price for Car" << endl;
cout << "7. Close the Program" << endl;
cout << "Choose an option: ";
cin >> option;
switch (option) {
case 1:
record(cars2);
break;
case 2:
break;
}
}
while(option != 7); //Going to be used to terminate the program
return 0;
}
void record(cars cars2[10]) { //Open the file then store everything in an
array of structs
int x;
ifstream temp; //Gonna be used as a temporary file to store stuff in
cout << "Enter the input file: ";
cin >> filea[10];
temp.open(filea); //This opens the file for reading
for(x = 0; x < 5; x++){
temp >> cars2[x].year >> cars2[x].make >> cars2[x].model >> cars2[x].price >> cars2[x].ava;
}
cout << "File has been read, please choose another option" << endl;
}
So this is still fairly early in my program but I want get these issues fixed so I just don't have a billion errors later on. When I compile the code it asks me for an input file name(as in my record function) so then I enter the file name. Afterwards the program just goes on the prints out the options given in the main and infinite number of times. But more importantly, when I do compile it, the message in my function
"File has been read, please choose another option"
isn't displayed so I figure that my program skips over that for some reason. Why is this causing a loop and why is it skipping over that print statement?
Any help would be appreciated!