# Answer to Question #6829 in C++ for noor

Question #6829

Write a C++ program for the calculation of the total price of the tickets that a group of visitors will pay to enter a museum .The regular price is 10.0 U.S per visitor. However students get 30% reduction , kids under 5 do not pay , kids between 5 and 10 have 50% reduction , and visitors above 60 have 20% reduction . In addition , if the number of visitors is more than 10, 15% reduction will be applied to the total price of the tickets.Write C++ program that ask the user to enter the number of student and number if the kids under 5 and the number of kids between 5 and 10 and the number of visitors above 60 and the number of visitors who do not have any special discounts .The program will calculate and display the total amount of the tickets requested ;

Expert's answer

Code of program:

#include <iostream>

using namespace std;

int main(int argc, char* argv[])

{

/// Regular price is $10.

const double regularPrice& = 10.0;

/// Discount for students in percents.

const double discountForStudents& = 0.3;

/// Discount for kids under 5 in percents.

const double discountForKidsUnder5& = 1.0;

/// Discount for kids between 5 and 10 in percents.

const double discountForKidsBetween5And10 = 0.5;

/// Discount for visitors above 60 in percents.

const double discountForVisitorsAbove60& = 0.2;

/// Discount for more than 10 visitors in percents.

const double discountForMoreThan10Visitors = 0.15;

/// Number of visitors that don't have any discount.

int numberOfVisitorsWithoutDiscount;

/// Number of students.

int numberOfStudents;

/// Number of kids under 5.

int numberOfKidsUnder5;

/// Number of kids between 5 and 10.

int numberOfKidsBetween5And10;

/// Number of visitors above 60.

int numberOfVisitorsAbove60;

/// Total visitors numbers.

int totalVisitorsNumber;

/// Read the number of visitors that are students.

cout<<"Please, input the number of visitors that are students: ";

cin>>numberOfStudents;

cout<<endl;

/// Read the number of kids under 5.

cout<<"Please, input the number of kids under 5: ";

cin>>numberOfKidsUnder5;

cout<<endl;

/// Read the number of kids between 5 and 10.

cout<<"Please, input the number of kids between 5 and 10: ";

cin>>numberOfKidsBetween5And10;

cout<<endl;

/// Read the number of visitors that are above 60.

cout<<"Please, input the number of visitors above 60: ";

cin>>numberOfVisitorsAbove60;

cout<<endl;

/// Read the number of other visitors.

cout<<"Please, input the number of other visitors: ";

cin>>numberOfVisitorsWithoutDiscount;

cout<<endl;

/// Calculate total number of visitors.

totalVisitorsNumber = ( numberOfStudents + numberOfKidsUnder5 + numberOfKidsBetween5And10 + numberOfVisitorsAbove60 + numberOfVisitorsWithoutDiscount);

/// Calculate total price as sum of prices for each category of visitors.

double totalPrice = regularPrice * (

& ( 1.0 - discountForStudents& ) * numberOfStudents +

& ( 1.0 - discountForKidsUnder5& ) * numberOfKidsUnder5 +

& ( 1.0 - discountForKidsBetween5And10 ) * numberOfKidsBetween5And10 +

& ( 1.0 - discountForVisitorsAbove60& ) * numberOfVisitorsAbove60 +

& numberOfVisitorsWithoutDiscount);

/// If total number of visitors are more than 10 use discount for this case.

if(totalVisitorsNumber > 10)

& totalPrice *= (1 - discountForMoreThan10Visitors);

/// Display total price.

cout<<"Total price is $"<<totalPrice<<endl;

return 0;

}

#include <iostream>

using namespace std;

int main(int argc, char* argv[])

{

/// Regular price is $10.

const double regularPrice& = 10.0;

/// Discount for students in percents.

const double discountForStudents& = 0.3;

/// Discount for kids under 5 in percents.

const double discountForKidsUnder5& = 1.0;

/// Discount for kids between 5 and 10 in percents.

const double discountForKidsBetween5And10 = 0.5;

/// Discount for visitors above 60 in percents.

const double discountForVisitorsAbove60& = 0.2;

/// Discount for more than 10 visitors in percents.

const double discountForMoreThan10Visitors = 0.15;

/// Number of visitors that don't have any discount.

int numberOfVisitorsWithoutDiscount;

/// Number of students.

int numberOfStudents;

/// Number of kids under 5.

int numberOfKidsUnder5;

/// Number of kids between 5 and 10.

int numberOfKidsBetween5And10;

/// Number of visitors above 60.

int numberOfVisitorsAbove60;

/// Total visitors numbers.

int totalVisitorsNumber;

/// Read the number of visitors that are students.

cout<<"Please, input the number of visitors that are students: ";

cin>>numberOfStudents;

cout<<endl;

/// Read the number of kids under 5.

cout<<"Please, input the number of kids under 5: ";

cin>>numberOfKidsUnder5;

cout<<endl;

/// Read the number of kids between 5 and 10.

cout<<"Please, input the number of kids between 5 and 10: ";

cin>>numberOfKidsBetween5And10;

cout<<endl;

/// Read the number of visitors that are above 60.

cout<<"Please, input the number of visitors above 60: ";

cin>>numberOfVisitorsAbove60;

cout<<endl;

/// Read the number of other visitors.

cout<<"Please, input the number of other visitors: ";

cin>>numberOfVisitorsWithoutDiscount;

cout<<endl;

/// Calculate total number of visitors.

totalVisitorsNumber = ( numberOfStudents + numberOfKidsUnder5 + numberOfKidsBetween5And10 + numberOfVisitorsAbove60 + numberOfVisitorsWithoutDiscount);

/// Calculate total price as sum of prices for each category of visitors.

double totalPrice = regularPrice * (

& ( 1.0 - discountForStudents& ) * numberOfStudents +

& ( 1.0 - discountForKidsUnder5& ) * numberOfKidsUnder5 +

& ( 1.0 - discountForKidsBetween5And10 ) * numberOfKidsBetween5And10 +

& ( 1.0 - discountForVisitorsAbove60& ) * numberOfVisitorsAbove60 +

& numberOfVisitorsWithoutDiscount);

/// If total number of visitors are more than 10 use discount for this case.

if(totalVisitorsNumber > 10)

& totalPrice *= (1 - discountForMoreThan10Visitors);

/// Display total price.

cout<<"Total price is $"<<totalPrice<<endl;

return 0;

}

## Comments

## Leave a comment