So this is my assignment and when I get the answer after typing yes for bringing vehicle the totals are wrong.
You have been contracted to write a C++ program to calculate the correct fare (using the
fare tariff above), based on an appropriate dialog with the customer. Believe it or not, the
above is actually a somewhat simplified form of the real fare structure! Your assignment
is to develop in C++ a non-graphical (non-GUI) version of the real online fare calculator,
which should ask exactly the same questions, in the same sequence, and produce exactly
the same results.
Example #1
Welcome to Gayathri’s Fare Calculator
Are you driving a vehicle onto the ferry? (y/n): y
Is the driver a senior citizen (65 or over) or disabled? (y/n): y
How many passengers in your vehicle? (excluding the driver)
Adults (age 19 – 64): 1
Senior Citizens (65 or older), or Disabled Persons: 1
Youth (5 -18 years old): 2
Is your vehicle over 7 feet, 6 inches in height? (y/n): y
How long is your vehicle in feet? 17
How many people in your group are traveling with a bicycle? 0
Your total fare is $115.55 Gayathri’s Fare Calculator
Example #2
Welcome to Gayathri’s Fare Calculator
Are you driving a vehicle onto the ferry? (y/n): y
Is the driver a senior citizen (65 or over) or disabled? (y/n): n
How many passengers in your vehicle? (excluding the driver)
Adults (age 19 – 64): 1
Senior Citizens (65 or older), or Disabled Persons: 1
Youth (5 -18 years old): 2
Is your vehicle over 7 feet, 6 inches in height? (y/n): y
How long is your vehicle in feet? 27
How many people in your group are traveling with a bicycle? 0
Your total fare is $171.25
Thank you for using Gayathri’s Fare Calculator
Example #3
Welcome to Gayathri’s Fare Calculator
Are you driving a vehicle onto the ferry? (y/n): n
How many adults (age 19 – 64): in your group? 2
How many senior citizens (65 or older), or disabled persons in your
group? 2
How many youth (5-18) in your group? 3
How many people in your group are traveling with a bicycle? 2
Your total fare is $62.15
Thank you for using Gayathri’s Fare Calculator
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
const double VehicleDriverO = 45.00;
const double VehicleDriverOS = 38.50;
const double VehicleDriverU = 36.05;
const double VehicleDriverUS = 29.55;
const double adultsFare = 12.95;
const double seniorFare = 6.45;
const double youthFare = 6.45;
const double bicycleFare = 2.00;
int main()
{
char vehicle;
double total;
char SeniorDriver;
int adults;
int oldpass;
char overHeight;
int youngpass;
int bicycles;
double overLength;
cout << "Welcome to My Fare Calculator" << endl;
cout << "Are You Bringing a vehicle on The Ferry ?";
cin >> vehicle;
if (vehicle == 'y')
{
cout << "\n\n" << "Is the Driver over 65 Years of age or disabled?";
cin >> SeniorDriver;
cout << "\n\n" << "Passengers going along with the driver" << "\n\n";
cout << "Adults (19-64 Years old):";
cin >> adults;
cout << "\n\n" << "Senior Citizens or disabled:";
cin >> oldpass;
cout << "\n\n" << "Young passengers 5-18 years old: ";
cin >> youngpass;
cout << "\n\n" << "Is your Vehicle over 7ft, 6in in height? ";
cin >> overHeight;
cout << "Vehicle length in feet: ";
cin >> overLength;
cout << "How many people in your group will travel with a bicycle?";
cin >> bicycles;
if (overLength < 14)
{
if (overHeight == 'n')
{
if (SeniorDriver == 'n')
{
total = VehicleDriverU + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = VehicleDriverUS + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
else if (overHeight == 'y')
{
if (SeniorDriver == 'n')
{
total = VehicleDriverU + 35.80 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = VehicleDriverUS + 35.80 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
}
if (overLength > 14 || overLength < 22)
{
if (overHeight == 'n')
{
if (SeniorDriver == 'n')
{
total = VehicleDriverO + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = VehicleDriverOS + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
else if (overHeight == 'y')
{
if (SeniorDriver == 'n')
{
total = VehicleDriverO + 44.75 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = VehicleDriverOS + 44.75 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
}
if (overLength > 22 || overLength < 30)
{
if (overHeight == 'n')
{
if (SeniorDriver == 'n')
{
total = 69.60 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = 69.60 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
else if (overHeight == 'y')
{
if (SeniorDriver == 'n')
{
total = 138.95 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
else if (SeniorDriver == 'y')
{
total = 138.95 + (adults * adultsFare) + (youngpass * youthFare) + (oldpass * seniorFare) + (bicycles * bicycleFare);
}
}
}
}
else
{
cout << "\n\n" << "How many Senior Citizens or disabled are in your group?";
cin >> oldpass;
cout << "\n\n" << "How many adults are in your group?:";
cin >> adults;
cout << "\n\n" << "How many in your group are youths (5-18):";
cin >> youngpass;
cout << "\n\n" << "How many in your group have Bicycles:";
cin >> bicycles;
total = oldpass * 6.45;
total = total + (adults * 12.95);
total = total + (youngpass * 6.45);
total = total + (bicycles * 2.00);
}
cout << "\n\n" << "your total fare cost is : $" << total;
cout << "\n\n\n" << "Thank you for using My Fare calculator!";
system("pause");
}
|