0

Hey I'm having a problem with a loop in my code. It's a pretty long problem, but it is a travel expenses program. I'm creating a function that calculates the meal expenses for the user. I have to get a total for two days(first day and last day). When I try to get a running total it doesen't work.
The number ends up about 2 or 4 numbers off.I know it's a little sloppy but I'll clean all the spacing and stuff up later. Here Ya go:

#include <iostream>
#include <fstream>
using namespace std;


int getDays(int);
double getDepartureTime();
double getArrivalTime(double);
double airFees(double);
double carRentalFees(double);
double getMilesDriven(double);
double getParkingTotal(double,double);
double getParkingSpent(double,double);
double getTaxiFees(double,double);
double employeeHotelExpense(double,double);
double getHotelExpense(double,double);
double getMealExpenses(double,double);
void timeEquivalent();
double breakFastFee = 0;
int main()
{
    int days=0, amount=0, departure_conference=0, departure_home=0,time = 0;
    double airFee=0,taxiFeesAllowed,parkingAllowed = 0,employeeHotelExpense = 0,employeeTaxiFees = 0, milesDriven=0, 
	parkingFees=0, taxiFees=0, yes=0,arrivalTime = 0;
    double carRentalFee = 0, hotel_expenses=0,departureTime = 0, meals=0,employeeMealExpenses = 0, parkingSpent = 0,allowableHotelExpense = 0
	,allowedMealTotal = 0,mealsSpent = 0;
    char employee[40];
	//timeEquivalent();
	//cout << "What Time Did You Arrive " <<endl;
	//cin >>time;
	
    days = getDays(days);
	timeEquivalent();
	departureTime = getDepartureTime();
	arrivalTime = getArrivalTime(arrivalTime);
	airFee = airFees(airFee);
	carRentalFee = carRentalFees(carRentalFee);
	milesDriven = getMilesDriven(milesDriven);
	parkingAllowed = 6 * days;
	parkingSpent = getParkingSpent(parkingSpent,days);
	taxiFeesAllowed = days * 10;
	employeeTaxiFees = getTaxiFees(taxiFees,days);
	allowableHotelExpense = 90 * days;
	employeeHotelExpense = getHotelExpense(employeeHotelExpense, days);
	employeeMealExpenses = getMealExpenses(departureTime,arrivalTime);
	cout << employeeMealExpenses <<endl;
	
	
	return 0;
	
	
	
}
	int getDays(int days)
	{
		cout << " How many Days did you stay on the trip " <<endl;
		cin >> days;

		while(days < 0)
		{
			cout <<"Please enter a value greater than 0 :D " <<endl;
			cin >> days;
		}
		

		return days;
	}

	double getDepartureTime()
	{
		double departureTime;
		
		cout << "Please Refer To The Menu Above and enter the time of departure in military\n";
		cout << "Time. For example if you departed at 7:30 enter 0730\n\n";
			
		cin >> departureTime;
		return departureTime;
	}

	double getArrivalTime(double arrivalTime)
	{
		cout << "Please refer to the menu above and enter the time you arrived back home in\n";
		cout <<" military format\n";
		cin >> arrivalTime;
		return arrivalTime;
	}
	double airFees(double airfee)
	{
		cout << " How Much Were Your Air Fees " <<endl;
		cin >> airfee;
		while(airfee < 0)
		{
			cout <<" Please enter a value greater than 0 :D " <<endl;
			cin >> airfee;
		}
		

		return airfee;
	}

	double carRentalFees(double carRentalFee)
	{
		cout << " How Much were Your Car Rental Fees " <<endl;
		cin >> carRentalFee;
		while(carRentalFee < 0)
		{
			cout <<"Please enter a value of 0 or greater :D " <<endl;
			cin >> carRentalFee;
		}
		

		return carRentalFee;
	}
	double getMilesDriven(double milesDriven)
	{
		const double mileRate = 0.27;
		cout << " How many miles did you drive, please enter 0 if a private vehicle was not used " <<endl;
		cin >> milesDriven;
		return mileRate * milesDriven;
	}

	double getParkingSpent(double parkingSpent, double days)
	{
		
		cout << " How Much Did You Spend on Parking " <<endl;
		cin >> parkingSpent;
		return parkingSpent*days;
	}
	double getTaxiFees(double taxiFees,double days)
	{
		cout << " Please Enter The Amount of Taxi Fees Please " <<endl;
		cin >> taxiFees;
		return taxiFees * days;
		
	}

	double getHotelExpense(double employeeHotelExpense,double days)
	{
		cout << " How Much Were Your Hotel Expenses " <<endl;
		cin >> employeeHotelExpense;
		return employeeHotelExpense * days;
	}
	double getMealExpenses(double departureTime,double arrivalTime)
	{
		 double breakFastFee = 0 ;
		 double lunchFee = 0 ;
		double dinnerFee = 0 ;
		int numberOfDays = 2 ;
		double total = 0;

		for(int days =1;days <=numberOfDays;days++)
		{
			
			if ( days < numberOfDays && departureTime > 000 && departureTime < 700)
			{
				cout << "Please Enter Your breakfast cost"<<endl;
				cin >> breakFastFee;


				cout << " Please Enter Your Lunch Cost " <<endl;
				cin >>lunchFee;

				cout << "Please Enter Your Dinner Cost " <<endl;
				cin >> dinnerFee;
			}

		 if (days < numberOfDays && departureTime > 700 && departureTime <=1200)
			{
				cout << "Please Enter Your Lunch Cost"<<endl;
				cin >> lunchFee;

				cout << "Please Enter Your Dinner cost "<<endl;
				cin >> dinnerFee;
	
		}
			if(days < numberOfDays && departureTime > 1201 && departureTime <= 1800)
			{
				cout << "Enter The Cost of Dinner " <<endl;
				cin >> dinnerFee;
			}

			if(days == numberOfDays && arrivalTime > 800 && arrivalTime<=1300)
			{
				cout <<"Enter The Cost of Breakfast " <<endl;
				cin >> breakFastFee;
			}

			if(days == numberOfDays && arrivalTime > 1301 && arrivalTime <= 1900)
			{
				cout << "Enter The Cost of Breakfast "<<endl;
				cin >> breakFastFee;

				cout << " Enter The Cost of Lunch " <<endl;
				cin >> lunchFee;
			}

			if(days == numberOfDays && arrivalTime > 1901)
			{
				cout << "Enter The Cost of Breakfast " <<endl;
				cin >> breakFastFee;

				cout << " Enter The Cost of Lunch " <<endl;
				cin >> lunchFee;

				cout << "Enter The Cost of Dinner " <<endl;
				cin >> dinnerFee;
	}
		
		total+=breakFastFee + lunchFee + dinnerFee;

		
	}
			
		return total;
	}
	
	
	
	void timeEquivalent()
	{
		
		cout <<"Regular Time " << "\t\t" <<"Military Time \n";
		cout <<"************"  << "\t\t" <<"***************"<<endl;
		cout <<"Midnight "	   << "\t\t" <<"0000 \n";
		cout <<"1:00a.m. "	   << "\t\t" <<"0100 \n";
		cout <<"2:00a.m. "     << "\t\t" <<"0200 \n";
		cout <<"3:00a.m. "     << "\t\t" <<"0300 \n";
		cout <<"4:00a.m. "     << "\t\t" <<"0400 \n";
		cout <<"5:00a.m. "     << "\t\t" <<"0500 \n";
		cout <<"6:00a.m. "     << "\t\t" <<"0600 \n";
		cout <<"7:00a.m. "     << "\t\t" <<"0700 \n";
		cout <<"8:00a.m. "	   << "\t\t" <<"0800 \n";
		cout <<"9:00a.m. "     << "\t\t" <<"0900 \n";
		cout <<"10:00a.m."     << "\t\t" <<"1000 \n";
		cout <<"11:00a.m."     << "\t\t" <<"1100 \n";
		cout <<"12:00p.m."     << "\t\t" <<"1200 \n";
		cout <<"1:00p.m. "     << "\t\t" <<"1300 \n";
		cout <<"2:00p.m. "     << "\t\t" <<"1400 \n";
		cout <<"3:00p.m. "     << "\t\t" <<"1500 \n";
		cout <<"4:00p.m. "     << "\t\t" <<"1600 \n";
		cout <<"5:00p.m. "     << "\t\t" <<"1700 \n";
		cout <<"6:00p.m. "     << "\t\t" <<"1800 \n";
		cout <<"7:00p.m. "     << "\t\t" <<"1900 \n";
		cout <<"8:00p.m. "     << "\t\t" <<"2000 \n";
		cout <<"9:00p.m. "     << "\t\t" <<"2100 \n";
		cout <<"10:00p.m."     << "\t\t" <<"2200 \n";
		cout <<"11:00p.m."     << "\t\t" <<"2300 \n";
		cout <<"Midnight "     << "\t\t" <<"0000 \n";
				

	}

if you test it out use 0600 for departure time and 0900 for military time.

Can somebody tell me why is it coming out wrong and direct me toward the correct way

Edited by jwill222: n/a

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by frogboy77
0

That's a big ask.
My suggestion would be to run the program with extra cout lines to find where the problem is occurring then post the smaller piece of code(that isn't working) for people to help you with.
There are some here who may slog through ~250 lines, but not many and not often.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.