Advertisement
Sierra_ONE

Taxi Meter

Oct 8th, 2023 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | Source Code | 0 0
  1. /*
  2. 9. Taxi Meter
  3. It’s the middle of the night, you just finished your shift, and the rain is pouring. Luckily, you find a vacant taxi. As you attempt to go in, the driver stops you and tells you that he can’t take you anywhere because his taxi meter is broken. Since you desperately want to go home, you make a deal with the taxi driver. You propose to manually calculate the total fare of your ride, luckily enough the driver trusts you and explains to you how the fare is calculated.
  4.  
  5. The taxi has a base fee of P40.00 for the first 250 meters. An additional P2.50 is added for every succeeding 200 meters. Compute and print the total fare that you would need to pay.
  6.  
  7. Inputs
  8. 1. Total distance travelled in meters
  9. */
  10.  
  11.  
  12. #include <stdio.h>
  13.  
  14. int main(){
  15.     int distance;
  16.  
  17.     printf("Enter the distance travelled (meters): ");
  18.     scanf("%d", &distance);
  19.  
  20.     double base = 40.00;
  21.     int bm = 250;
  22.     double add = 2.50;
  23.     int am = 200;
  24.  
  25.     int s1 = distance - bm;
  26.     int s2 = (s1 + am - 1) / am;
  27.     double s3 = s2 * add;
  28.     double total = base + s3;
  29.  
  30.     printf("Total cost = P%.2f", total);
  31.  
  32.  
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement