Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I cannot get this code to recognize the minium fare of 5.00 when it runs. everyt

ID: 3583645 • Letter: I

Question

I cannot get this code to recognize the minium fare of 5.00 when it runs. everything else seems to calculate correctly. Please check other calculations to see if they matchu p with program instructions below.

Thanks

This program should calculate the fare for a cab ride based on the rates provided below. Ask the user to input distance (measured to 1/10 of mile), number of passengers, and if going to/coming from the airport. Calculate fare for trip using these rates:

Minimum fare: $5.00 (fares less than this rounded up to $3.50).

$1.80 per mile (charged by 1/10 of mile. 2.1 miles = $3.78).

1st additional passenger, if more than 1 rider: $1.00.

Each additional passenger (after 1st additional passenger): $0.50.

Airport surcharge: $2.00.

#include <stdio.h>
int main()
{
int distance, passenger, airport;
float fare;

//reading distance
printf(" Input distance: ");
scanf("%d", &distance);

//reading number of passengers
printf(" Enter number of passenger ");
scanf("%d", &passenger );

//selecting type of travel
printf(" Select type of travel: 1 - Going to Airport 2 Non Airport travel: ");
scanf("%d", &airport);

// minimum fare
     fare = 5.00;
if (airport ==1)
{fare= (distance*1.80) + 2;}
//charges for distance ( $1.80 per mile )
else {fare = distance*1.80;};

if (passenger <=1)
{fare=fare+1;}

else if (passenger>1)
{fare = fare + 1 + (0.50* (passenger-1));

}
//Total fare
printf("Your fare cost: %f ", fare);


return 0;
}

Explanation / Answer

#include<stdio.h>
int main()
{
int dist,pass,airport;
float fare;
printf(" INPPUT distance:");
scanf("%d",&dist);
printf(" No of Passengers");
scanf("%d",&pass);
printf(" type of travel : 1- AIRPORT NON airport:");
scanf("%d",&airport);
if(airport==1)
{
fare=((dist*1.80)+2);
}
else
{
fare=dist*1.80;
}
if(pass<=1)
{
fare=fare+1;
}
else if (pass>1)
{
fare=fare+1+(0.50*(pass-1));
}
if (fare<=0)
{
fare=3.0;
}
printf("YOUR FARE COST:%f ",fare);
}

Try this code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote