In: Computer Science
(IN C LANGUAGE) The cost to become a member of a fitness center is as follows:
(a) the senior citizens discount is 30%
(b) if the membership is bought and paid for 12 or more months, the discount is 15%
(c) if more than five personal training sessions are bought and paid for, the discount on each session is 20%
Write a 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 that prompts for the price per month of a membership and the cost of each personal trainer session
a function that prompts for all of the necessary information to determine the cost of a membership
a function to determine the membership cost
STARTER CODE:
#include <stdio.h>
#include <stdbool.h>
void setPrices(...);
void getInfo(...);
double membershipCost(...);
void displayCenterInfo();
int main()
{
}
void displayCenterInfo()
{
printf("Welcome to Stay Healty and Fit
center.\n");
printf("This program determines the cost of a new
membership.\n");
printf("If you are a senior citizen, then the discount
is 30%% of the regular membership price.\n");
printf("If you buy membership for twelve months and
pay today, the discount is 15%%.\n");
printf("If you buy and pay for 6 or more personal
training session today, the discount on each session is
20%%.\n\n");
}
// sourceCode.c
#include <stdio.h>
#include <stdbool.h>
void setPrices(double*, double*);
void getInfo(bool*, bool*, bool*, int*, int*);
double membershipCost(double, int, double, int, bool, bool, bool);
void displayCenterInfo();
int main()
{
bool seniorCitizen;
bool boughtSixOrMoreSessions;
bool paidTwelveOrMoreMonths;
int numberOfMembershipMonths;
int numberOfPersonalTrainingSessions;
double regularMembershipChargesPerMonth;
double costOfOnePersonalTrainingSession;
double memberCost;
displayCenterInfo();
// Note: & is used to pass the variable as by reference to the function
setPrices(®ularMembershipChargesPerMonth, &costOfOnePersonalTrainingSession);
getInfo(&seniorCitizen, &boughtSixOrMoreSessions, &paidTwelveOrMoreMonths, &numberOfMembershipMonths, &numberOfPersonalTrainingSessions);
// calculate getInfo
memberCost = membershipCost(regularMembershipChargesPerMonth, numberOfMembershipMonths, costOfOnePersonalTrainingSession,
numberOfPersonalTrainingSessions, seniorCitizen, boughtSixOrMoreSessions, paidTwelveOrMoreMonths);
printf("$%.2lf\n",memberCost);
return 0;
}
void displayCenterInfo()
{
printf("Welcome to Stay Healthy and Fit center.\n");
printf("This program determines the cost of a new membership.\n");
printf("If you are a senior citizen, then the discount is 30%% of the regular membership price.\n");
printf("If you buy membership for twelve months and pay today, the discount is 15%%.\n");
printf("If you buy and pay for 6 or more personal training session today, the discount on each session is 20%%.\n\n");
}
void setPrices(double* regMemPrice, double* personalTrSesCost)
{
printf("Please enter the cost of regular Membership per month: ");
scanf("%lf",&*regMemPrice);
printf("Please enter the cost of one personal training session: ");
scanf("%lf",&*personalTrSesCost);
}
void getInfo(bool* senCitizen, bool* bSixOrMoreSess, bool* paidTwMnth, int* nOfMonths, int* nOfPersonalTrSess)
{
//Senior Citizen Verification
char userInputSenior;
printf("Are you Senior? Please enter 'Y' or 'N': ");
scanf(" %c",&userInputSenior);
if (userInputSenior == 'y' || userInputSenior == 'Y') {
*senCitizen = true;
} else{
*senCitizen = false;
}
//Number of personal training session.
printf("Enter the number of personal training sessions bought: ");
scanf("%d",&*nOfPersonalTrSess);
if (*nOfPersonalTrSess > 5){
*bSixOrMoreSess = true;
}
else{
*bSixOrMoreSess = false;
}
//Number of months
printf("Enter the number of months you are paying for: ");
scanf("%d",&*nOfMonths);
if (*nOfMonths >= 12){
*paidTwMnth = true;
} else{
*paidTwMnth = false;
}
}
double membershipCost(double regMemPricePerMth, int nOfMonths, double personalTrSesCost, int nOfPersonalTrSess,
bool senCitizen, bool bSixOrMoreSess, bool paidTwMnth)
{
double finalMembershipCost, finalSessionCost;
//Session Discount
if (bSixOrMoreSess) {
personalTrSesCost = (personalTrSesCost * 0.8);
} else {
personalTrSesCost = personalTrSesCost;
}
//Month Discount
if (paidTwMnth) {
regMemPricePerMth = regMemPricePerMth * 0.85;
} else {
regMemPricePerMth = regMemPricePerMth;
}
finalMembershipCost = regMemPricePerMth * nOfMonths;
finalSessionCost = personalTrSesCost * nOfPersonalTrSess;
// Check if Senior Citizen Discount Applies
if (senCitizen) {
return (finalMembershipCost * 0.7) + finalSessionCost;
} else {
return finalMembershipCost + finalSessionCost;
}
}
// Screenshots:
// Output:
// If you found the answer helpful do give a Thumbs Up!!