Advertisement
Spocoman

04. Transport Price

Sep 4th, 2023
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int kilometers;
  8.     cin >> kilometers;
  9.  
  10.     string timeOfDay;
  11.     cin >> timeOfDay;
  12.  
  13.     const double TAXI_STARTING_PRICE = 0.70;
  14.     const double TAXI_PRICE_PER_KILOMETER = (timeOfDay == "day" ? 0.79 : 0.90);
  15.     const double BUS_PRICE_PER_KILOMETER = 0.09;
  16.     const double TRAIN_PRICE_PER_KILOMETER = 0.06;
  17.  
  18.     double taxiPrice = TAXI_STARTING_PRICE + TAXI_PRICE_PER_KILOMETER * kilometers;
  19.     double busPrice = BUS_PRICE_PER_KILOMETER * kilometers;
  20.     double trainPrice = TRAIN_PRICE_PER_KILOMETER * kilometers;
  21.  
  22.     double cheapestPrice = kilometers < 20 ? taxiPrice : kilometers < 100 ? busPrice : trainPrice;
  23.    
  24.     cout.setf(ios::fixed);
  25.     cout.precision(2);
  26.    
  27.     cout << cheapestPrice << endl;
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement