Multiple If Statement Homework Help
Sometimes we need to Execute Statements with different conditions. Say for example:
In the website of Indian Railways, while you are booking an online ticket, following discounts on the tickets are there:
If age of passenger is less than 5 years then 100% discount.
If age of passenger is more than 5 but less than 12 years then 50% discount.
If age of passenger is more than 12 but less than 26 years then 10% discount.
If age of passenger is more than 60 years then 25% discount.
The following example will illustrate this problem:
#include <stdio.h>
#include <conio.h>
int main()
{
{//}int age;
printf(“Enter your age: ”);
scanf(“%d”,&age);
if (age <= 5)
{
printf(“you have 100% discount on your ticket.”);
}
if ((age > 5) && (age <= 12))
{
printf(“you have 50% discount on your ticket.”);
}
if ((age > 12) && (age <= 26))
{
printf(“you have 10% discount on your ticket.”);
}
if (age > 60)
{
printf(“you have 25% discount on your ticket.”);
}
return;
}
In the above example && is used, which is Logical Operator. This means, If first statement and also second statement is true then only the statement will be executed.
- If Statement
- Multiple if statement
- If else statement
- Nested if else statement
- Else if statement
- Conditional Operator
- The switch statement