Electricity bill calculation using if.... else if statement in C Programming

The monthly electricity bill is computed as
a) Minimu Rs 80|- upto 20 units
b) Rs 7.30 per unit for next 100 units
c) Rs 9.00 per unit for any unit beyond 120 unit
Write a program to compute monthly bill for given no. of units consumed by customer.
Solution : code goes like this :

/* Program to calculate electricty bill using if... else if  */
#include<stdio.h>
int main()
{
float unit, billAmt;
printf("Enter consume unit : ") ;
scanf("%f",&unit);
if(unit<=20)
printf("\n The total billAmount is Rs 80");
else if(unit>20&&unit<=120)
{
    billAmt=(unit-20)*7.30+80;
    printf("\n The total billAmount is Rs %.2f",billAmt);
}
else
{
    billAmt=unit*9;
    printf("\n The total billAmount is Rs %.2f",billAmt);
}
return 0;
}

Output: Unit upto 20
-------------------------
 












Output : Unit upto 120
---------------------------











Output : Unit beyond 120
-------------------------------











I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment