Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Illustration of else if ladder

Posted By: Maisie Hughes     Category: C Programming     Views: 4834

Illustration of else if ladder.

Code for Illustration of else if ladder in C Programming

 main()                                                      
   {                                                           
       int  units, custnum;                                    
       float charges;                                          
                                                          
       printf("Enter CUSTOMER NO. and UNITS consumed\n");      
       scanf("%d %d", &custnum, &units);                       
       if (units <= 200)                                       
          charges = 0.5 * units;                               
       elseif (units <= 400)                                  
   charges = 100 + 0.65 * (units - 200);                   elseif (units <= 600)                             
                    charges = 230 + 0.8 * (units - 400);       
                 else                                          
                    charges = 390 + (units - 600);             
                                                               
       printf("\n\nCustomer No: %d: Charges = %.2f\n",         
              custnum, charges);                               
   }
Output                                                      
                                                               
   Enter CUSTOMER NO. and UNITS consumed 101  150              
   Customer No:101 Charges = 75.00                             
                                                               
   Enter CUSTOMER NO. and UNITS consumed 202  225              
   Customer No:202 Charges = 116.25                            
                                                               
   Enter CUSTOMER NO. and UNITS consumed 303  375              
   Customer No:303 Charges = 213.75                            
                                                               
   Enter CUSTOMER NO. and UNITS consumed 404  520              
   Customer No:404 Charges = 326.00                            
                                                              
   Enter CUSTOMER NO. and UNITS consumed 505  625              
   Customer No:505 Charges = 415.00      
  
Share: 


Didn't find what you were looking for? Find more on Illustration of else if ladder Or get search suggestion and latest updates.

Maisie Hughes
Maisie Hughes author of Illustration of else if ladder is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!