please can you help to get this answer :


I have a problem in the result of kilometer formula






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: ";


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



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



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

infile>>dayfees>> c >> Day;

if (Kilometers<=500)


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



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


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



else if (Kilometers>1500)


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



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

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

outfile<<"================ ==========="<<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;







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.