1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/* Bryan Kobashi
bryan.kobashi@gmail.com
Lab 4 CIS 22A
*/
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//what can be pulled back out of functions
double fareCalc (double minutes, double distance, double multiplier, double baseFare, double perMinute, double perMile, double minimum);
void output (double fare, string name);
int main()
{
// define variables
string name;
double minutes;
double distance;
char surge;
char option;
double multiplier;
double baseFare;
double perMinute;
double perMile;
double minimum;
double fare;
cout << "Enter first and last name then press enter: ";
//Make sure to use getline since it's two words.
getline (cin, name);
cout << "Enter the length of your ride in minutes: ";
cin >> minutes;
cout << "Enter the distance of your trip in miles: ";
cin >> distance;
cout << "Enter your budget option, S for SUV, X for budget, and L for luxury: ";
cin >> option;
option = (char) toupper(option);
cout << "Is this a surge trip? Enter Y for yes, and N for no: ";
cin >> surge;
surge = (char) toupper(surge);
//Use switch (option) for different car options.
switch (option)
{
case 'L':
baseFare = 5.00;
perMinute = 0.50;
perMile = 2.75;
minimum = 10.55;
break;
case 'S':
baseFare = 15.00;
perMinute = 0.90;
perMile = 3.75;
minimum = 25.00;
break;
case 'X':
baseFare = 2.00;
perMinute = 0.22;
perMile = 1.15;
minimum = 6.55;
break;
}
if (surge == 'Y'){
cout << "Enter the surge multiplier: ";
cin >> multiplier;
}
//What will be pulled out of this function
fare = fareCalc(minutes, distance, multiplier, baseFare, perMinute, perMile, minimum);
output(fare, name);
return 0;
}
//pulling back these variables that were defined in the main function
double fareCalc (double minutes, double distance, double multiplier, double baseFare, double perMinute, double perMile, double minimum)
{
double fare;
//fare calculation
fare = (baseFare * multiplier) + (perMinute * minutes) + (perMile * distance);
if (fare < minimum){
fare = minimum;}
else{
fare = fare;
//returning the value of the fare
return fare;
}
}
//pulling back the fare and string variables
void output(double fare, string name)
{
//set precision and fixed for easily readable format
cout << "Fare " << setprecision(2) << fixed;
cout << "Rider's name: " << name << endl;
cout << "Total: $" << fare;
//printing out the name and fare
|