Calculate Electricity Bill Using Slab Rates in C

This program calculates an electricity bill using slab-based rates: Rs.1.50/unit up to 100 units, Rs.3.00/unit for units from 101-200, and Rs.5.00/unit for units above 200.

C Program

#include <stdio.h>

int main() {
    int units;
    float bill;

    printf("Enter number of units consumed: ");
    scanf("%d", &units);

    if (units <= 100) {
        bill = units * 1.50;
    } else if (units <= 200) {
        bill = (100 * 1.50) + (units - 100) * 3.00;
    } else {
        bill = (100 * 1.50) + (100 * 3.00) + (units - 200) * 5.00;
    }

    printf("Electricity bill for %d units: Rs. %.2f\n", units, bill);

    return 0;
}

Explanation

  • The if-else ladder checks which slab the total units falls into, from lowest to highest.
  • For units in the second slab, only the portion above 100 is billed at Rs.3.00, while the first 100 units are still billed at Rs.1.50 — the slabs are cumulative, not a flat rate applied to the whole total.
  • Similarly, for units above 200, the first 100 units and the next 100 units keep their own rates, and only the remainder above 200 is billed at Rs.5.00.

Sample Output

Enter number of units consumed: 250
Electricity bill for 250 units: Rs. 700.00

Leave a Comment