Write a program to calculate an air ticket fare after discount, given the following conditions : If passenger is (i) below 14 years then there is 50% discount on fare. (ii) above 50 years, 20% discount. (iii) above 14 and below 50 then 10% discount only
Answers
Answer:
#include <stdio.h>
void Below14(float price){
float final;
final = price / 2;
printf("Price to pay is: £%.2f", final);
}
void Above50(float price){
float final;
final = price - ((price / 10) * 2);
printf("Price to pay is: £%.2f", final);
}
void Age14to50(float price){
float final;
final = price - (price / 10);
printf("Price to pay is: £%.2f", final);
}
void main()
{
int age;
//fare of ticket
float Adult = 35.00; // 14 to 50
float Child = 20.00; // Below 14
float Senior = 27.50; //Above 50
printf("Please enter the passenger's age: ");
scanf("%d", &age);
if(age<14){
Below14(Child);
}
else if((age>=14) && (age<=50)){
Age14to50(Adult);
}
else if(age>50){
Above50(Senior);
}
else{
printf("Error!");
}
}
Step-by-step explanation: