C Program 2 – Electricity Bill calculation

This program is to display the electricity bill calculation based on the number of units consumed every month

Input : the number of units – variable name – unit

Output – Amount of rupee – variable name – amount

Logic:

Units Rupees
1-50 units 0.75/unit
51-100 0.85/unit
101-200 1.50/unit
201-300 2.20/unit
>300 3.00/unit

In all the cases, there will be service charge of Rs.20 will be collected.

#include <stdio.h>
#include <conio.h>
int main()
{
    float amount=0,units;;
    printf("Enter the number of units");
    scanf("%f", &units);
    if(units <=50)
    {
     amount = units * 0.75;       
    }   
    else if(units >50 && units <=100)
    {
         amount=0.75 * 50 + 0.85*(units-50);
    }
    else if(units >100 && units <200)
    {
         amount=(0.75*50) + (0.85*50 )+ (1.5 *(units-100));
    }
    else if(units >200 && units <300)
    {
         amount=(0.75*50) + (0.85*50 )+ (1.5 *100) + (2.20 *(units-200));
    }
    else
    {
         amount=(0.75*50) + (0.85*50 )+ (1.5 *100) + (2.20 * 100) +(3.0*(units-300));
    }
    amount=amount+(0.2*amount);
    printf("The total electricity bill is %f", amount);
    getch();
    return 0;
}

Popular Posts