Friday, 2 November 2012

The If Else statement


to execute one group of statements if the expression evaluates to true and another group of statements if the expression evaluates to false

example:

If his basic salary is less than RM 1500, then HRA = 10% of basic salary and DA = 90% of basic salary. If his salary is either equal to or above RM 1500, then HRA = RM 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.
so the coding is as follow:
#include <stdio.h>
int main(void)
{
    int basicsallary, a, aa, sallary, sallaries;
    // get input
    printf("\nplease enter your basic sallary=");
    scanf("%d",&basicsallary);
    a = basicsallary - (0.1*basicsallary);
    aa = basicsallary - 100 ;
    sallary = a + 500 ;
    sallaries = aa + 800 ;
   
    //condition
                 if (basicsallary > 1500)
                 {
                  printf("your new basic sallary is = %d", a);
                 }
                 if (basicsallary < 1500)
                 {
                  printf("your new basic sallary is = %d,aa");
                 }
                 if (a > 3000)
                 {
                 printf("your new total sallary is = %d", sallary);
                 }
                 if(aa < 3000)
                 {
                 printf("your new total sallary is = %d",sallaries);
                 }
                  scanf("%d",&basicsallary);  
                 
return 0;          
}

No comments:

Post a Comment