In: Computer Science
Using C language: (Note: If a family of 4, apply family of 3 cost plus the cost of 1 participant. K800 is the fixed cost for a family of 3.)
A bus company organizes a tour. The tour is open for 4 days and participants can register for the number of days they would like to participate in the tour. Each participant would pay K 300 for the tour per day, a family of 3 would pay K 800 per day, and a family of 5 would pay K 1000 per day Write a program that calculates the cost of participating in the tour The program reads the number of participants input by the user, and the number of days of participation Based on these variables and the prices outlined for the tour, the program should then calculate the total cost of participating in the tour If a participant(s) registers for more than 2 days of the tour, the first 2 days will be at full price while the days after will be at half price Include the program algorithm in your design.
Below is the code which return the cost of participants. It is running perfect on CodeBlocks compiler
The program first check whether the no of participants are 1,2,3,4,5 or more than 5 and the corresponding cost is calculated.
After this, It is multiply with the no of days.
for example . no of participants = 9, no of days =3;
cost= 1000+800+300=2100
final cost = 2100*2 + 2100/2= 5250
------------------------------------------------------------------------------------------------
#include<stdio.h>
void main()
{
int number_of_days,number_of_participants,no; // no is divisor used
to calculate the days which are more than 5
int cost=0;
scanf("%d%d",&number_of_participants,&number_of_days);
if(number_of_participants==1 || number_of_participants==2)
cost+=300*number_of_participants;
else if(number_of_participants==5)
cost+=1000;
else if(number_of_participants==3)
cost+=800;
else if(number_of_participants==4)
cost+=800+300;
else if(number_of_participants>5)
{
no=number_of_participants/5;
number_of_participants=number_of_participants%5;
cost=cost+1000*no;
if(number_of_participants==1 || number_of_participants==2)
{
cost+=300*number_of_participants;
}
else if(number_of_participants==3)
cost+=800;
else if(number_of_participants==4)
cost+=800+300;
}
if(number_of_days==2)
{
cost=cost*2;
}
else if(number_of_days>2)
cost=cost*2+(cost*(number_of_days-2))/2;
printf("cost of partipants : %d",cost);
}
----------------------------------------------------------------------------------------------------------------