Monday, January 02, 2012

Program with multiple statements within if

Exercise 13
Program to find out the bonus amount of the employees. If the service duration of a particular employee is more than or equal to 3 years then the bonus amount is $2500.00 else the bonus amount is $1000.00.

Solution:

/* Program to calculate the bonus amount of the employee */
#include<stdio.h>
#include<conio.h>



void main()
{
int cy,yj,ys,bonus=1000;
printf("Enter the current Year ");
scanf("%d", &cy);
printf("Enter the year of joining ");
scanf("%d", &yj);
ys=cy-yj;

if (ys>=3)
  {
    bonus=2500;
    printf("This employee has completed 3years of service");
  }

printf("The bonus amount of this employee is = $ %d", bonus);
getch();
}

Explanation: In this program, we are initially assigning the value of bonus as 1000, and if the year of service if more than or equal to 3 years, then the value of bonus changes to 2500 and the along with that, the program prompts "The employee has completed 3 years of service", thus multiple statements are performed within if statement. And if the year of service is less than 3 years then the bonus amount does not changes and the system does not prompts that the employee has completed 3 years of service and the program counter directly comes to the printf statement of the bonus amount of the employee.

Output of the following program is as follows:

Case-I
Enter the current Year 2012
Enter the year of joining 2007
This employee has completed 3years of service
The bonus amount of this employee is = $ 2500

Case-II

Enter the current Year 2012
Enter the year of joining 2010
The bonus amount of this employee is = $ 1000

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...