C Program to Calculate Electricity Bill

Through the C program to calculate electricity bill example tutorial, we will learn today how to calculate electricity bill in c program. Here we have added the calculate electricity bill using if else in C programming. Program to find net electricity bill in C program easily.

We have write a c program to calculate electricity unit charge and calculate the total electricity bill according to the given condition:

  • For the first 50 units Rs. 0.50/unit
  • For the next 100 units Rs. 0.75/unit
  • For the next 100 units Rs. 1.20/unit
  • For the unit above 250 Rs. 1.50/unit

An additional surcharge of 20% is added to the bill.

C Program to calculate electricity bill

#include <stdio.h>

int main()
{
    int unit;
    float amt, total_amt, sur_charge;

    /* Input unit consumed from user */
    printf("Enter total units consumed: ");
    scanf("%d", &unit);


    /* Calculate electricity bill according to given conditions */
    if(unit <= 50)
    {
        amt = unit * 0.50;
    }
    else if(unit <= 150)
    {
        amt = 25 + ((unit-50) * 0.75);
    }
    else if(unit <= 250)
    {
        amt = 100 + ((unit-150) * 1.20);
    }
    else
    {
        amt = 220 + ((unit-250) * 1.50);
    }

    /*
     * Calculate total electricity bill
     * after adding surcharge
     */
    sur_charge = amt * 0.20;
    total_amt  = amt + sur_charge;

    printf("Electricity Bill = Rs. %.2f", total_amt);

    return 0;
}

The above c program output:

I hope this work for you.

Leave a Comment