Write a program to calculate an Air ticket fare after discount, given the following conditions:

0 votes
asked Nov 22 by (120 points)

If passenger is below 14 years then there is 50% discount on fare
If passenger is above 50 years then there is 20% discount on fare
If passenger is above 14 and below 50 then there is 10% discount on fare.

 

7 Answers

+1 vote
answered Nov 23 by anonymous

Let's say you have the age of the person in an int variable (if not, do a simple input to an int) 

int age, price;

double newprice = 0;
if(age < 14) newprice = price-(0.5*price);

else if (age > 14 && age < 50) newprice = price - (0.1*price);

else if (age > 50) newprice = price - (0.2*price);

+1 vote
answered Nov 24 by anonymous
#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!");
    }
    
}
0 votes
answered Nov 27 by (510 points)
0 votes
answered Nov 28 by aryan gupta
#include<stdio.h>
#include<conio.h>
void
main ()
{
  
float fare, discount;
  
int age;
  
fare = 30;
  
printf ("Enter your age");
  
scanf ("%d", &age);
  
if (age < 14)
    
    {
      discount = (fare / 100) * 40;
      
fare = fare - discount;
      
printf ("fare=%f", fare);
    }
  
  else if (age > 50)
    
    {
      discount = (fare / 100) * 20;
      
fare = fare - discount;
      
printf ("fare=%f", fare);
    
}
  
  else
    
    {
      
discount = (fare / 100) * 10;
      
fare = fare - discount;
      
printf ("fare=%f", fare);
    
}

}
0 votes
answered Nov 29 by (160 points)
#include <stdio.h>

int main()
{
    int age;
    float fare;
    
    printf("Enter passenger age: ");
    scanf("%i", &age);
    printf("Enter fare: ");
    scanf("%f", &fare);
    
    if (age < 14) {
        printf("Your air fare of $%.2f will be discounted to $%.2f", fare, fare/2);
    }
    else if (age > 50) {
        printf("Your air fare of $%.2f will be discounted to $%.2f", fare, fare * .80);
    }
    else {
        printf("Your air fare of $%.2f will be discounted to %.2f", fare, fare * .90);
    }

    return 0;
}
0 votes
answered Nov 29 by Rounak Anand

According to the question there will be two required variables for storing the values ,the one is age of the person and second is the fare of the person.

Age should be of integer type and Fare can be of  float type.

I'm writing this on C language for better understanding for the user.

#include <stdio.h>
main()
{
    int age;  
    float fare=1000;  // fare can be anything ..
    printf("Enter your age:\n");  // asking age of the person 
    scanf("%d",&age);  //taking person age as an input
     if(age<14){          // checking condition using if statement
         fare=(fare-(fare/2));  // performing operation on the fare according to the question
         printf("Your fare is :%f",fare);  // printing  the calculated fare after the operation
     }
    else if(age>14 && age<50){     // checking another condition
         fare=(fare-(fare/10));  // 
performing operation on the fare according to the question
         printf("Your fare is :%f",fare); //printing  the calculated fare after the operation
    }
    else{                                                                   
     fare=(fare-(fare/5));  //
performing operation on the fare according to the question
         printf("Your fare is :%f",fare); //printing  the calculated fare after the operation
        }
} // closing the main function. 

0 votes
answered Dec 1 by (220 points)
/*Write a program to calculate an Air ticket fare after discount, given the following conditions:
+1
vote
asked 5 days ago by (130 points)
If passenger is below 14 years then there is 50% discount on fare
• If passenger is above 50 years then there is 20% discount on fare
• If passenger is above 14 and below 50 then there is 10% discount on fare*/
#include<stdio.h>
void main()
{
    float fair=3000, netfair, discount;
    netfair = fair;
    discount = fair;
    int age;
    printf("Enter the age of the passanger:");
    scanf("%d", &age);
    if(age<14)
    discount*= 0.5;
    else if((age>=14)||(age<50))
    discount*= 0.1;
    else
    discount*= 20;
    netfair= fair-discount;
    printf("fair price is: %f\n applying discount, fair is: %f", fair, netfair);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...