Advertisement
Brandan

Calculates a fare and fuel charge for a ferry.

Oct 30th, 2013
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. // Brandan Tyler Lasley
  2. // Sources: None
  3. // 10/20/2013 18:29
  4. // Calculates a fare and fuel charge for a ferry.
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int main () {
  12.  
  13.     // Vars
  14.  
  15.     // People & Fuel
  16.     double personAdult = 13.00;
  17.     double personChild = 6.50;
  18.     double personFuel = 1.25;
  19.  
  20.     // Vehicles
  21.     double vehicle = 43.00;
  22.     double vehicleLarge = 2.15;
  23.     double vehicleFuel = 4.15;
  24.  
  25.     // Trucks and trailers.
  26.     double vehicleOversize = 69.00;
  27.     double VehicleOversizeFuel = 10.40;
  28.     double vehicleOversizeLarge = 3.45;
  29.  
  30.     // Calc Vars
  31.     string answer;
  32.     double temp;
  33.     double totalFare = 0;
  34.     double totalFuel = 0;
  35.     double vehicleLength = 0;
  36.  
  37.     // Add 0 to end of single digit numbers, also prevent it from going over 2 (it wouldn't anyways)
  38.     cout << fixed << setprecision(2);
  39.  
  40.     cout << "Welcome to Brandan's Fare Calculator" << endl;
  41.    
  42.     cout << "How many adults (age 12+) are in your party: ";
  43.     cin >> temp;
  44.     // Add fare and fuel
  45.     totalFare = totalFare + (personAdult * temp);
  46.     totalFuel = totalFuel + (personFuel * temp);
  47.  
  48.     cout << "How many children (age 5-11) are in your party: ";
  49.     cin >> temp;
  50.     // Add fare and fuel
  51.     totalFare = totalFare + (personChild * temp);
  52.     totalFuel =  totalFuel +(personFuel * temp);
  53.  
  54.     cout << "Are you driving a vehicle onto the ferry? (y/n): ";
  55.     cin >> answer;
  56.  
  57.     if ((answer == "Y") || (answer == "y")) {
  58.         // Add declare vehicle length
  59.         cout << "What is the length of the vehicle in feet?: ";
  60.         cin >> vehicleLength;
  61.         cout << "Is the vehicle over 7 feet high? (y/n): ";
  62.         cin >> answer;
  63.  
  64.         // Calculate Vehicle Lengh price
  65.     if ((answer == "Y") || (answer == "y")) {
  66.         if (vehicleLength < 20) {
  67.             totalFare = totalFare + (vehicleOversize);
  68.         } else {
  69.             totalFare = totalFare + (vehicleOversize + (vehicleOversizeLarge * (vehicleLength - 20)));
  70.         }
  71.             totalFuel = totalFuel + (VehicleOversizeFuel);
  72.         } else {
  73.             if (vehicleLength < 20) {
  74.                 totalFare = totalFare + (vehicle);
  75.             } else {
  76.                 totalFare = totalFare + (vehicle + (vehicleLarge * (vehicleLength - 20)));
  77.             }
  78.                 totalFuel = totalFuel + (vehicleFuel);
  79.         }
  80.     }
  81.  
  82.     // Print out total
  83.     cout << "Your fare is $" << totalFare << " plus a fuel surcharge of $" << totalFuel << endl;
  84.     cout << "The total amount payable is $" << (totalFare + totalFuel) << endl;
  85.     cout << "Thank you for using Brandan's Fare Calculator" << endl;
  86.  
  87.     // would print out a recept, but i dont remember whats suppose to go on it.
  88.  
  89.     // Exit footer
  90.     getchar();
  91.     getchar();
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement