Question: I need assistance with the following code per the instructions + feedback received by inst regarding my code. This program should calculate the fare for

I need assistance with the following code per the instructions + feedback received by inst regarding my code.

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 int main() { int passengers,airport; float fare, distance;

printf(" Please Input Distance: "); //user input total distance scanf("%f",&distance); //reading distance input //

printf(" Total Number of Passengers: "); //user input total number of passengers including self // scanf("%d",&passengers); //reading passenger input //

printf(" Select travel type: 1- Going to/from airport \t 2 Not to/from airport: "); //airport yes/no to determine surcharge application // scanf("%d",&airport); //reading airport input //

if(airport==1) //if input = airport yes/ 1 = $2 surcharge // { fare = (distance*1.80) + 2; // airport surcharge applied at $2.00 // } else //'or else' // { fare = distance*1.80; // 'or else' /if NOT airport/ no additional $2 fee/ just fare @ $1.80xdistance // } if(passengers==2) // if just 1 additional rider (2 riders total) // { fare= fare + 1; // $1.00 fee for 1 additional rider (2 riders) // } else if(passengers>2) // more than 2 riders = $1 for 1st additional rider , and + $0.50 for ea add rider (3+) total// { fare= fare + 1 +(0.50*(passengers - 1)); // +1 rider= $1. +2 rider= $1.50. +3 rider= $2.00 -- subtract 1 for the 1st non fee rider// } if(fare<=5.00) // minimum fare is $5.00 // { printf("Your fare cost: 5.00 "); // print fare minimum if fare is less than $5.00 // } else printf("Your fare cost: %.2f ", fare); //print total fare costs per user input calculations //

return 0;

}

The feedback I received was "You should handle each part of the fare separately, add each to the total fare, and then move on to the next part of the fare calculation. Combining the calculation for the mileage charge and the airport surcharge as you do on line 29 is not logical because there is no relationship between the mileage and the airport surcharge. If the per-mile rate were to change, you would have to update line 29 and 33. It would be best to carry out this calculation at just one location."

I cant seem to figure out a logical way to do this with the if/else functions I have chosen to use, rather only to re-write this entirely. Any help would be much appreciated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!