Thursday, January 05, 2012

Program with if-else Statement

Exercise 14

Write a program to find the gross salary of individual employee. The conditions to find the gross salary are as follows:

If the basic salary is less than $1500, then HRA is 10% of basic and DA is 90% of basic.

And if the basic salary is more than or equal to $1500, then HRA is $500 and DA is 98% of basic.

The basic salary is inputted through the keyboard by the user.

Solution:
/* Program to find out the gross salary */
#include<stdio.h>
#include<conio.h>



void main()
{
float bs, hra, da, gs;
printf(“Enter the 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 = $%.2f”, gs);
getch();
}
Explanation: Here we have two possibilities, one is for basic less than $1500 and the other is for the basic more than or equal to $1500. Thus the condition used in this program is for basic less than $1500. If the condition is true, the group of statements after the if statement within braces will be performed, i.e., HRA will be 10% of basic and DA will be 90% of basic and if the condition becomes false, i.e., basic not less than $1500 or greater than or equal to $1500 then the the group of statements after the else statement within braces will be performed, i.e., HRA will be $500 and DA will be 98% of basic, And at last the gross salary will be calculated by summing up the basic, HRA and DA and the same will be prompted on the screen.
Output of the program is as follows:
Case-I
Enter the Basic salary = $1000
Gross Salary = $2000.00
Case-II
Enter the Basic salary = $2000
Gross Salary = $4460.00

No comments:

Post a Comment

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...