Decision making with IF ELSE statement

Share:

Decision making with IF ELSE statement:

IF ELSE statement

The if statement by itself will execute a single statement, or a group of statements, when the expression following if evaluates to true. It does nothing when the expression evaluates to false. Can we execute one group of statements if the expression evaluates to true and another group of statements if the expression evaluates to false? 

if ( this condition is true )
{
Execute this statement;
}
Else
{
Execute this statement;
}

Example 2
In a company an employee is paid as under:

If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic
salary. If the employee's salary is input through the keyboard write a program to find his gross salary.

Answer:

/* Calculation of gross salary */
main( )
{
float bs, gs, da, hra ;
printf ( "Enter basic salary " ) ;
scanf ( "%f", &bs ) ;
if ( bs < 1500 )
{
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
}
else
{
hra = 500 ;
da = bs * 98 / 100 ;
}
gs = bs + hra + da ;
printf ( "gross salary = Rs. %f", gs ) ;
}
IMPORTANT LINKS HARE:
Decision making with IF statement
Learn More →
Decision making with IF ELSE statement
Learn More →
Nested if-elses
Learn More →
Forms of if
Learn More →
Decisions Using Switch
Learn More →
Consider the following program
Learn More →
The output of this program would be
Learn More →
Switch Versus if-else Ladder
Learn More →
The goto statement
Learn More →
LOOPS
Learn More →
The While Loop
Learn More →
The General form of While is as shown below
Learn More →
The For Loop
Learn More →
The General form of for statement is as under
Learn More →
Write down the simple interest program using for
Learn More →
Nesting of Loops
Learn More →
When you run this program you will get the following output
Learn More →
The do-while statement
Learn More →
The General form of do-while loop is:
Learn More →
Break Statement
Learn More →
Continue Statement
Learn More →