Question: 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

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 Gayathris 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 Gayathris Fare Calculator Example #2 Welcome to Gayathris 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 Gayathris Fare Calculator Example #3 Welcome to Gayathris 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 Gayathris Fare Calculator

My calculations come out incorrect when I run the program.

<

#include #include #include

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 << " " << "Is the Driver over 65 Years of age or disabled?"; cin >> SeniorDriver; cout << " " << "Passengers going along with the driver" << " "; cout << "Adults (19-64 Years old):"; cin >> adults; cout << " " << "Senior Citizens or disabled:"; cin >> oldpass; cout << " " << "Young passengers 5-18 years old: "; cin >> youngpass; cout << " " << "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 << " " << "How many Senior Citizens or disabled are in your group?"; cin >> oldpass; cout << " " << "How many adults are in your group?:"; cin >> adults; cout << " " << "How many in your group are youths (5-18):"; cin >> youngpass; cout << " " << "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 << " " << "your total fare cost is : $" << total; cout << " " << "Thank you for using My Fare calculator!"; system("pause");

}>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!