Skip to content

Instantly share code, notes, and snippets.

@allisons
Created July 12, 2009 00:03
Show Gist options
  • Save allisons/145447 to your computer and use it in GitHub Desktop.
Save allisons/145447 to your computer and use it in GitHub Desktop.
// This is the Sliter BC Ferry Calculator Program (sliterbcferries.cpp)
// Written by: Allison Sliter
// Date: 11 July 2009
// Sources: Malik, D.S. C++ Programming: from Problem Analysis to Project Design,
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
char vehicle, vehicHeight;
int adults, chldrn, vehicLength;
double fare, adGas, chldGas, vehiGas, oversizeGas, total, gas;
adGas = 1.25;
chldGas = 1.25;
vehiGas = 4.15;
oversizeGas = 10.40;
cout << fixed << setprecision(2);
cout << "Welcome to Allison Sliter's Fare Calculator.";
cout << "\nHow many adults (age 12 or over) are in your party? ";
cin >> adults; cout << "How many children (age 5 to 11) are in your party? ";
cin >> chldrn; cout << "Are you driving a vehicle onto the ferry (y/n)? ";
cin >> vehicle;
switch (vehicle)
{
case 'n':
fare = ((adults * 13.00) + (chldrn * 6.50));
gas = (adults * adGas) + (chldrn * chldGas);
total = gas + fare;
cout << endl;
cout << "Your fare is $"; cout << fare; cout << " plus a fuel surcharge of "; cout << gas;
cout << "\nThe total amount payable is $"; cout << total;
cout << "\nThank you for using Allison Sliter's fare Calculator.";
break;
case 'y':
cout << "What is the length of your vehicle in feet? ";
cin >> vehicLength; cout << "Is your vehicle over 7 feet tall? ";
cin >> vehicHeight;
switch (vehicHeight) {
case 'y':
if (vehicLength > 20)
{(fare = (adults * 13.00) + (chldrn * 6.50) + 69.00 + ((vehicLength - 20) * 3.45));
gas = ((adults * adGas) + (chldrn * chldGas) + oversizeGas);
total = gas + fare;}
else {fare = ((adults * 13.00) + (chldrn * 6.50) + 69.00);
gas = ((adults * adGas) + (chldrn * chldGas) + oversizeGas);
total = gas + fare;}
cout << endl;
cout << "Your fare is $"; cout << fare; cout << " plus a fuel surcharge of "; cout << gas;
cout << "\nThe total amount payable is $"; cout << total;
cout << "\nThank you for using Allison Sliter's fare Calculator.";
break;
case 'n':
if (vehicLength > 20)
{fare = ((adults * 13.00) + (chldrn * 6.50) + 43.00 + ((vehicLength - 20) * 2.15));
gas = (adults * adGas) + (chldrn * chldGas) + vehiGas;}
else
{fare = ((adults * 13.00) + (chldrn * 6.50) + (43.00));
gas = (adults * adGas) + (chldrn * chldGas) + vehiGas; }
total = fare + gas;
cout << endl;
cout << "Your fare is $"; cout << fare; cout << " plus a fuel surcharge of "; cout << gas;
cout << "\nThe total amount payable is $"; cout << total;
cout << "\nThank you for using Allison Sliter's fare Calculator.";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment