Showing posts with label Illustration of the conditional operator. Show all posts
Showing posts with label Illustration of the conditional operator. Show all posts

llustration of the conditional operator

Program 18) An employee van apply for a loan at the beginning of every six months but he will be sanctioned the amount according to the following company rules:
Rule 1 : An employee cannot enjoy mote than two loan at
             any point of time.
Rule 2 : Maximum permissible total loan is limited and 
             depends upon the category of the employee.

This program is process loan applications and to sanction loans.
        
                                  PROGRAM

#define MAXLOAN 50000
main ( )
 {
        long int loan1, loan2, loan3, sancloan, sum23 ;
        printf (" Enter the values of previous 
                           two loans : \n") ;
        scanf ("%1d %1d &loan1 &loan2 ) ;
         
        printf ("nEnter the value of new loan : \n") ;
        scanf ("%1d", &loan3) ;

        sum23 = loan2 + loan3 ;
        sancloan = (loan1>0)? 0 : ((sum23>MAXLOAN)?
                                                MAXLOAN - loan2 : loan3) ;
        printf ("\n\n") ;
        printf ("Previous loans pending: \n%1d %1d\n", 
                                  loan1, loan2) ;
        printf ("Loan requested = %1d\n", loan3) ;
        printf ("loan sanctioned = %1d\n", sanclon) ;
       getch ( ) ;
 }

Output:       Enter the values of previous two loans :
                   0  20000
                   Enter the value of new loan :
                   45000
                   Previous loans pending :
                   0  20000
                   Loan requested = 45000
                   Loan sanctioned = 30000
                   Enter the values of previous two loans :
                   1000  15000
                   Enter the value of new loan :
                   25000
                   Previous loans pending :
                   1000  15000
                   Loan requested  = 25000
                   Loan sanctioned = 0


The program uses the following variables:
    Loan3  -  present loan amount requested
    Loan2  -  previous loan amount pending
    Loan1  -  previous to previous loan pending
    sum23 -   sum of loan2 and loan3
    sanclon  -  loan sanctioned 
The rules for sanctioning new loan are:
    1. Loan1 should be zero
    2. Loan2 + Loan3 should not be more than MAXLOAN.