Advertisement
Spocoman

08. Fuel Tank - Part 2

Sep 4th, 2023
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     const double GAS_PRICE = 0.93;
  8.     const double DIESEL_PRICE = 2.33;
  9.     const double GASOLINE_PRICE = 2.22;
  10.    
  11.     string fuel;
  12.     cin >> fuel;
  13.  
  14.     double liters;
  15.     cin >> liters;
  16.  
  17.     string card;
  18.     cin >> card;
  19.  
  20.     double cardDiscount = card == "Yes" ? (fuel == "Gasoline" ? 0.18 : fuel == "Diesel" ? 0.12 : 0.08) : 0;
  21.     double quantitativeDiscount = liters > 25 ? 0.10 : liters >= 20 ? 0.08 : 0;
  22.  
  23.     double totalSum = (((fuel == "Gas" ? GAS_PRICE : fuel == "Diesel" ? DIESEL_PRICE : GASOLINE_PRICE) - cardDiscount) * liters) * (1 - quantitativeDiscount);
  24.  
  25.     cout.setf(ios::fixed);
  26.     cout.precision(2);
  27.  
  28.     cout << totalSum << " lv." << endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement