In: Computer Science
C Code
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 (use pass by pointer parameters) a function that prompts for all of the necessary information to determine the cost of a membership (use pass by pointer parameters) a function to determine the membership cost (use pass by value parameters)
For Example: This program determines the cost of a new membership.
If you are a senior citizen, then the discount is 30% of the regular membership price.
If you buy membership for twelve months and pay today, the discount is 15%
If you buy and pay for 6 or more personal training session today, the discount on each session is 20%
Enter the cost of a regular membership per month: 100
Enter the cost of one personal training session: 11
Are you a senior citizen (Y|y/N|n): n
Enter the number of personal training sessions bought: 3
Enter the number of month you are paying for: 13
The membership cost = $1138.00
Source Code :
#include<stdio.h>
int cpm,cpt,nt,nm;
char sc;
void general_info_fitness_center()
{
printf("\nThis program determines the cost of a new membership.\nIf
you are a senior citizen, then the discount is 30% (of the regular
membership price).\nIf you buy membership for twelve months and pay
today, the discount is 15%.\nIf you buy and pay for 6 or more
personal training session today, the discount on each session is
20%\n"); //showing info about fitness center and prices
}
void prompt_price()
{
printf("\nEnter the cost of a regular membership per month:
");
scanf("%d",&cpm);// cost per month
printf("Enter the cost of one personal training session:" );
scanf("%d",&cpt); //cost per training session
}
void prompt_necessary_info()
{
printf("\nAre you a senior citizen (Y|y/N|n):");
scanf(" %c",&sc); //senior citizenship
printf("Enter the number of personal training sessions
bought:");
scanf("%d",&nt); //number of training sessions
printf("Enter the number of month you are paying for:");
scanf("%d",&nm); //number of months
}
void membership_cost(char sc,int nt,int nm,int cpm,int
cpt)
{
float month_discount,training_discount,total_price;
float total_month=nm*cpm; //total charge for total month without
any discount
float total_training=nt*cpt; //total charge for total training
sessions without any discount
if(nt>=6) //if number of training sessions are morethan 5
{
training_discount=(total_training*20)/100; //then discount is
20%
total_training=total_training-training_discount; //then substract
discount from total charge for training sessions
}
if(sc=='Y' || sc=='y') //if he is senior citizen
{
month_discount= (total_month*30)/100; //then discount is 30%
total_month=total_month-month_discount; //then substract discount
from total charge for months
}
else //if he is not senior citizen
{
if(nm>=12) //and number of month paying is greater than or equal
to 12
{
month_discount= (total_month*15 )/100; //then discount is 15%
total_month=total_month-month_discount; //then substract discount
from total charge for months
}
}
total_price=total_month+total_training; //then total charges for
membership is sum of total charge for total month and total charge
for total training sessions
printf("\nThe membership cost :%f\n",total_price); //printing
membership cost
}
int main()
{
general_info_fitness_center();
prompt_price();
prompt_necessary_info();
membership_cost(sc,nt,nm,cpm,cpt);
return 0;
}
Code Screenshots :
OUTPUT :