please can you help to get this answer :

Capture.PNG

I have a problem in the result of kilometer formula

 

#include<iostream>

#include<fstream>

#include<iomanip>

#include<string>

using namespace std;

int main()

{

ifstream infile;

ofstream outfile;

string outfilename;

string filename;

string Kilo;

string dayfees;

double f1, f2, f3, Kilometers, cost_km, cost_day ;

int Day, daynamber ;

char c;

const double Tax_value=0.18;

const int Dayfees=45;

cout<<"Enter number of renal days: ";

cin>>daynamber;

cout<<"Enter number of Kilometers you plan travel: ";

cin>>Kilometers;

cout<<endl;

cout<<"Enter the input file name: ";

cin>>filename;

 

infile.open(filename.c_str());

outfile.open("carRentalFees.out");

 

infile>> Kilo >> c >> f1>> c >>f2>> c >>f3;

infile>>dayfees>> c >> Day;

if (Kilometers<=500)

{

cost_km=float (Kilometers*f1+Tax_value*(Kilometers*f1));

cost_day=daynamber*Dayfees+Tax_value*(daynamber*Dayfees);

}

else if((Kilometers>=501)&&(Kilometers<=1500))

{

cost_km=float ((500*f1)+((Kilometers-500)*f2)+((500*f1)+((Kilometers-500)*f2)*Tax_value));

cost_day=daynamber*Dayfees+Tax_value*(daynamber*Dayfees);

}

else if (Kilometers>1500)

{

cost_km=float ((500*f1)+(1000*f2)+(Kilometers-1500)*f3+((500*f1)+(1000*f2)+(Kilometers-1500)*f3)*Tax_value);

cost_day=daynamber*Dayfees+0.18*(daynamber*Dayfees);

}

outfile<<"Renting a car for "<<daynamber<<"days to travel"<<Kilometers<<"Kms would cost: "<<endl;

outfile<<"kilometer formla Day formula"<<endl;

outfile<<"================ ==========="<<endl;

outfile<<fixed<<showpoint<<setprecision(3);

outfile<<setw(16)<<cost_km<<setw(19)<<cost_day<<endl;

 

if (cost_km>cost_day)

outfile<<"you have to choose the kilometer formula"<<endl;


else if (cost_km=cost_day)

outfile<<"you have to choose the day formula or the kilometer formula"<<endl;


else if (cost_km>=cost_day)


outfile<<"you have to choose the day formula"<<endl;

 

 

 

infile.close();

outfile.close();

 

return 0;

}

Edited 1 Year Ago by sunshine102030

This might be irrelevant to what the issue might be with the program, but I see a few typos in your syntax.

You have NOT supplied enough info about your problem.

Using some functions would help to see each of the problem steps.

Also ... using some global constants could help here ...
maybe for something like the following:

if total_kms >= STEP3_RATE_KMS use_rate = STEP3_RATE;
else if total_kms >= STEP2_RATE_KMS use_rate = STEP2_RATE;
else use_rate = STEP1_RATE;

Edited 1 Year Ago by David W

This article has been dead for over six months. Start a new discussion instead.