179,631 views
5 votes
5 votes
The cost to become a member of a fitness center is as follows: the membership fee per month is $50.00 the personal training session fee per session is $30.00 the senior citizens discount is 30% if the membership is bought and paid for 12 or more months, the discount is 15%; If more than five personal training sessions are bought and paid for, the discount on each session is 20%. Write a program that determines the cost of a new membership. Your program must contain a function that displays the general information about the fitness center and its charges, a function to get all the necessary information to determine the membership cost, and a function to determine the membership cost. Your program must also be a menu driven program. Given the user 2 options as follows: Calculate membership costs. quit this program.

User Luismiyu
by
3.3k points

1 Answer

7 votes
7 votes

Answer:

#include <iostream>

using namespace std;

void information(){

cout<<"Welcome to the portal"<<endl;

cout<<"The membership fee per month is $50.00"<<endl;

cout<<"The personal training session fee is $30.00"<<endl;

cout<<"The senior citizens discount is 30%"<<endl;

cout<<"If the membership is bought and paid for 12 or more months, the discount is 15%;"<<endl;

cout<<"If more than five personal training sessions are bought and paid for, the discount on each session is 20%."<<endl;

}

void getInfo(bool &senior, int &months, int &personal){

cout<<"Are you senior citizen y/n ? : ";

char choice;

cin>>choice;

if(choice=='y' || choice=='Y'){

senior = true;

}else{

senior = false;

}

cout<<"Enter number of months for membership : ";

cin>>months;

cout<<"Enter number of personal training session : ";

cin>>personal;

}

double calcCost(bool senior, int months, int personal){

double cost=0;

double memberShipCost=months*50;

double trainingCost=personal*30;

if(personal>5){

trainingCost*=.80; //discount on personal training

}

if(months>=12){

memberShipCost*=.85; //discount on membership

}

cost = memberShipCost+trainingCost;

//discount for seniors

if(senior){

cost = cost*.70;

}

return cost;

}

int main() {

information();

cout<<"Select an option"<<endl;

char choice;

while(true){

cout<<endl<<endl;

cout<<"a. Calculate membership costs."<<endl;

cout<<"b. Quit program."<<endl;

cout<<"Enter your choice : ";

cin>>choice;

bool senior=true;

int months,personal;

if(choice=='a'){

getInfo(senior,months,personal);

double cost=calcCost(senior, months, personal);

cout<<"The calculated cost is $"<<cost<<endl;

}else if(choice=='b'){

break;

}

}

return 0;

}

Step-by-step explanation:

User Nawara
by
4.0k points