You are hired by an ice-skating center. Your job is to write a program to do calculate the admission fees as follows:
• Children 6 and younger $8.50
• Children 7 and older. $10.50
• Adults $12.00
• Seniors $9.50
There will be 10% tax. PNG students, staff, and faculty will receive 25% discount (before tax).
Design an algorithm and write a C++ program that prompts the user to input the number of tickets in each group age and if the user is a student, staff, or faculty at PNG. The program calculates and outputs the admission fees as illustrated in the sample runs.
Output:
Are you PNG student, staff, or faculty?
Enter Y for yes or enter N for no: Y
Enter the number of children 6 and younger : 1
Enter the number of children 7 and older : 1
Enter the number of adults : 1
Enter the number of seniors : 1
******You received %25 Discount*****
Subtotal ......$30.38
Tax ...........$3.04
Total .........$33.41
Algorithm:
The program:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const double CHLD6 = 8.50;
const double CHLD7 = 10.50;
const double ADULT = 12.00;
const double SENIOR = 9.50;
const int PNG_DISCOUNT = 25;
const int TAX = 10;
int chld6, chld7, adults, seniors;
bool isPNG;
char ans;
double subtotal, tax, total;
cout << "Are you PNG student, staff, or faculty?" << endl;
cout << "Enter Y for yes or enter N for no: ";
ans = cin.get();
if (ans == 'y' || ans == 'Y') {
isPNG = true;
}
else {
isPNG = false;
}
cout << "Enter the number of children 6 and younger : ";
cin >> chld6;
cout << "Enter the number of children 7 and older : ";
cin >> chld7;
cout << "Enter the number of adults : ";
cin >> adults;
cout << "Enter the number of seniors : ";
cin >> seniors;
cout << endl;
subtotal = chld6*CHLD6 + chld7*CHLD7 + adults*ADULT + seniors*SENIOR;
if (isPNG) {
cout << " ******You received %" << PNG_DISCOUNT << " Discount*****"
<< endl << endl;
subtotal *= (1 - PNG_DISCOUNT/100.0);
}
tax = subtotal * TAX/100.0;
total = subtotal + tax;
cout << fixed;
cout << "Subtotal ......$" << setprecision(2) << subtotal << endl;
cout << "Tax ...........$" << setprecision(2) << tax << endl;
cout << "Total .........$" << setprecision(2) << total << endl;
return 0;
}
Comments
Leave a comment