I am having some trouble finishing this exercise here. I am supposed to have this program run normally, then ask for an employee ID or name, and then store the data under that name in a txt file, and then loop the program. I have the entire program finished, just stuck on having to put in that loop and have the txt file store the data under the user input name/number. How do I solve this? (the code is very long, I will add it in a comment.)
int numDays(int daysOnTrip)
{
cout << "How many days did you spend on this business trip? ";
cin >> daysOnTrip;
while (daysOnTrip < 1)
{
cout << "\nInvalid input. The number of days spent on a trip\n"
<< "has to be greater than or equal to 1.\n"
<< "How many days have you spent on this business trip? ";
cin >> daysOnTrip;
}
return daysOnTrip;
}
double getDepartureTime(double departureTime)
{
cout << "\nAt what time was your departure on the first day? ";
cin >> departureTime;
while (departureTime < 0 || departureTime > 24.00)
{
cout << "\nInvalid input. The departure time can not be\n"
<< "negative. Example Input: 00.00 - 24.00\n"
<< "At what time was your departure on the first day? ";
cin >> departureTime;
}
}
return arrivalTime;
}
double getRoundTripFares(double roundTripFares)
{
cout << "\nWere there any round trip airfares? $ ";
cin >> roundTripFares;
while (roundTripFares < 0)
{
cout << "\nInvalid input. The amount of airfares can not\n"
<< "be negative.\n"
<< "Were there any round trip airfares? $ ";
cin >> roundTripFares;
}
return roundTripFares;
}
double getCarRentalCost(double carRentalCost)
{
cout << "\nHave you had any car rental cost? $ ";
cin >> carRentalCost;
while (carRentalCost < 0)
{
cout << "\nInvalid input. The amount of car rental cost can not\n"
<< "be negative.\n"
<< "\nHave you had any car rental cost? $ ";
cin >> carRentalCost;
}
return carRentalCost;
}
double getMilesDriven(double milesDriven)
{
cout << "\nHow many miles have you driven in your own car? ";
cin >> milesDriven;
while (milesDriven < 0)
{
cout << "\nInvalid input. The number of miles driven can not\n"
<< "be negative.\n\n"
<< "\nHow many miles have you driven in your own car? ";
cin >> milesDriven;
}
return milesDriven;
}
double getParkingFees (double parkingFee
while (parkingFees < 0)
{
cout << "\nInvalid input. The parking fees can not be negative.\n\n"
<< "Have you had to pay any parking fees? $ ";
cin >> parkingFees;
}
return parkingFees;
}
double getTaxiFees (double taxiFees)
{
cout << "\nWere there any taxi fees? $ ";
cin >> taxiFees;
while (taxiFees < 0)
{
cout << "\nInvalid input. The taxi fees can not be negative.\n\n"
<< "Were there any taxi fees? $ ";
cin >> taxiFees;
}
return taxiFees;
}
double getRegistrationFees (double registrationFees)
{
cout << "\nWere there any conference or seminar registration fees? $ ";
cin >> registrationFees;
while (registrationFees < 0)
{
cout << "\nInvalid input. The registration fee can not be negative.\n"
<< "Were there any conference or seminar registration fees? $ ";
cin >> registrationFees;
}
return registrationFees;
}
double getHotelExpenses(double hotelExpenses)
{
cout << "\nHave you had any hotel expenses? $ ";
cin >> hotelExpenses;
while (hotelExpenses < 0)
{
cout << "\nInvalid input. The hotel expenses can not be negative.\n"
<< "Have you had any hotel expenses? $ ";
cin >> hotelExpenses;
}
if (timeOfDeparture > 07.00)
{
cout << "\nHow much did you pay for breakfast on your first day? $ ";
cin >> breakfastFirstDay;
}
while (breakfastFirstDay < 0.0)
{
cout << "\nInvalid input. The cost for breakfast can not be negative.\n"
<< "How much did you pay for breakfast on your first day? $ ";
cin >> breakfastFirstDay;
}
if (timeOfDeparture < 12.00)
{
cout << "\nHow much did you pay for lunch on your first day? $ ";
cin >> lunchFirstDay;
}
while (lunchFirstDay < 0.0)
{
cout << "\nInvalid input. The cost for lunch can not be negative.\n"
<< "How much did you pay for lunch on your first day? $ ";
cin >> lunchFirstDay;
}
if (timeOfDeparture < 18.00)
{
cout << "\nHow much did you pay for dinner on your first day? $ ";
cin >> dinnerFirstDay;
}
while (dinnerFirstDay < 0.0)
{
cout << "\nInvalid input. The cost for dinner can not be negative.\n"
<< "How much did you pay for dinner on your first day? $ ";
cin >> dinnerFirstDay;
}
if (timeOfArrival < 08.00)
{
cout << "\nHow much did you pay for breakfast on your last day? $ ";
cin >> breakfastLastDay;
}
while (breakfastLastDay < 0.0)
{
cout << "\nInvalid input. The cost for breakfast can not be negative.\n"
<< "How much did you pay for breakfast on your last day? $ ";
cin >> breakfastLastDay;
}
if (timeOfArrival > 13.00)
{
cout << "\nHow much did you pay for lunch on your last day? $ ";
cin >> lunchLastDay;
}
while (lunchLastDay < 0.0)
{
cout << "\nInvalid input. The cost for lunch can not be negative.\n"
<< "How much did you pay for lunch on your last day? $ ";
cin >> lunchLastDay;
}
if (timeOfArrival > 19.00)
{
cout << "\nHow much did you pay for dinner on your last day? $ ";
cin >> dinnerLastDay;
}
while (dinnerLastDay < 0.0)
{
cout << "\nInvalid input. The cost for breakfast can not be negative.\n"
<< "How much did you pay for dinner on your last day? $ ";
cin >> dinnerLastDay;
}
cout << "\n\n\t\tBusiness Trip Expenses\n\n"
<< "Number of Days:\t\t"
<< setw(26) << right << numDays
<< setw(15) << right
<< "\nTime of Departure:\t\t"
<< setw(21) << right << timeDeparture
<< setw(15) << right
<< "\nTime of Arrival:\t\t"
<< setw(21) << right << timeArrival
<< setw(15) << right
<< "\n\nCost of Air Fare:\t\t"
<< setw(13) << right << "$ "
<< setw(8) << right << costAirFare
<< "\nCost of Car Rental:\t\t"
<< setw(13) << right << "$ "
<< setw(8) << right << costCarRental
<< "\nCost of Taxi Fare:\t\t"
<< setw(13) << right << "$ "
<< setw(8) << right << costTaxi
<< "\nCost of Registration:\t\t"
<< setw(13) << right << "$ "
<< setw(8) << right << costRegistration
<< "\nCost of Overnight Hotel stay:\t\t"
<< setw(5) << right << "$ "
<< setw(8) << right << costHotel
<< "\nCost of Breakfast on First Day:\t\t"
<< setw(5) << right << "$ "
<< setw(8) << right << costBreakfastFirst
<< "\nCost of Lunch on First Day:\t\t"
<< setw(5) << right << "$ "
<< setw(8) << right << costLunchFirst
<< "\nCost of Dinner on First Day:\t\t"
<< setw(5) << right << "$ "
<< setw(8) << right << costDinnerFirst
<< "\nCost of Breakfast on Last Day:\t\t"
<< setw(5) << right << "$ "
<< setw(8) << right << costBreakfa
cout << "\n\nSub-Total: "
<< setw(34) << right << "$ "
<< setw(8) << right << costSubtotal;