Question
Single Passenger Fare with no checked in baggage Adult Passenger (age 14-64) $147.30 Senior Passenger (age 65+) $137.75 Child Passenger (under 14) $110.25 Infant Passenger
Single Passenger Fare with no checked in baggage
Adult Passenger (age 14-64) $147.30
Senior Passenger (age 65+) $137.75
Child Passenger (under 14)
$110.25
Infant Passenger (under 2) $0.00
Family X is going for a vacation from Portland to Las Vegas. The one way ticket fare is
given above. Write a program to calculate the one way airfare including baggage cost for
family X.
1) Remember, the program allows only adults, 18 or older to purchase tickets. Use if
statement to verify the purchaser age.
2) Next ask if the user want to purchase ticket or not. Use switch. If yes, continue to
step 3, otherwise end the program.
3) The user may input any number of adults, seniors, children, infants and bags.
4) Baggage Cost: The cost of baggage is zero, if there are no checked in baggage. The
cost of first baggage is $20 for each bag. The cost of second bag is $35 for each bag.
5) The program will output the total purchase price = Total one way fare of all
passenger + Total baggage cost.
6) The output should be formatted to two decimal places.
*************This is what I have now***********Need some correction**********
#include
using namespace std;
int main() { int age, nad, nsc, ncd, nif, nbg, costbg = 0; int conf; float totcost = 0.0, round_cost = 0.0; cout << ("Hello! Welcome to XYZ Airlines, Pleased to serve you"); cout << (" Please enter your age :"); cin >> age; if (age < 18) // Checking for age { cout << (" Sorry, You are not authorised to purchase tickets"); return 0; } else { cout << (" Thanks for confirming age, Enter '1' if you like to purchase Tickets "); //asking for prompt cin >> conf; switch (conf) //using prompt { case 1: { cout << (" Cool!, Please enter the number of adults(aged 14-64) you want to purchase tickets for:"); // take user input of particulars cin >> nad; cout << (" Thanks!, Please enter the number of senior citizens(>65 aged) you want to purchase tickets for:"); cin >> nsc; cout << (" Great!, Please enter the number of Children(2-14aged) you want to purchase tickets for:"); cin >> ncd; cout << (" Awesome!, Please enter the number of infants(under 2 aged) you want to purchase tickets for:"); cin >> nif; cout << (" Last one...!, Please enter the number of Bags you are going to checkin:"); cin >> nbg; { if (nbg == 1) ///calculate baggage cost based on number of bags costbg = 20; else if (nbg > 1) costbg = 20 + (nbg - 1) * 35; totcost = nad * 147.30 + nsc * 137.75 + ncd * 110.25 + costbg; //total cost of passengers and baggage round_cost = (totcost * 100) / 100; cout << (" The Total cost is: " , totcost); cout << (" Round cost is: ", round_cost); }
break; } default: cout << ("Thanks!, This Service helps you buy tickets to LAS VEGAS");
}
} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started