I want to check if the user inputs a number that is the same as in my drivers.txt file. The file looks like this:
Angela 07483774637 1000 1100
Mark 07362543432 1100
Dave 07869878907 1200 1100
Name, number, and time booked for all the drivers. Check if the user inputs a time that is the same as the last 2 columns. If that time is booked up on all drivers (i.e. if all drivers have 1100 next to their names) then say that a taxi is not available for that time and if the time is free on one, then say that a taxi is available.
Should know that as soon as it finds one instance of the same number as the user then does not say that a taxi is available for that time (e.g. checks column 1 first then if it has that number then do not continue (i.e. Mark has 1100, but the next column is blank so program may think that Mark is available for 1100)). Later I will implement a writing to file function so that the users write to the file the times booked instead of me writing them manually.
userTime2 = the users input
The relevant code so far:
struct Driver
{
string firstName;
double number;
int timeBooked;
};
const int MAXDRIVERS = 3;
struct Driver cab;
void searchDrivers()
{
cout << "\nSearching for drivers..." << endl;
ifstream inFile;
inFile.open("drivers.txt");
if (!inFile)
{
cout << "error reading file";
}
else
{
for (int i = 0; i < MAXDRIVERS; i++)
{
inFile >> cab.firstName[i] >> cab.number[i] >> cab.timeBooked[i];
if (userTime2 == cab.timeBooked[i])
{
cout << "unavailable" << endl;
}
else
{
cout << "car available" << endl;
driverIndex = i;
confirmBooking();
}
}
}
}
What do I need to add/change to this to make it work? Thank you.