C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Electricity bill calculation (slab-based)

Introduction

Electricity boards often calculate bills using a slab rate system, where the cost per unit depends on how many units are consumed.

For example, a sample slab system might be:

Units Consumed

Rate per Unit

0 – 100 units

₹ 1.50

101 – 200 units

₹ 2.50

201 – 300 units

₹ 4.00

Above 300 units

₹ 5.00

The bill is calculated progressively.
Additional fixed charge or tax can be added if required.

For example, if someone consumes 250 units, the calculation is:

  • First 100 units × ₹1.50 = ₹150
  • Next 100 units × ₹2.50 = ₹250
  • Remaining 50 units × ₹4.00 = ₹200
    Total = ₹600

 

C Program: Electricity Bill Calculation (Slab-Based)

C

#include <stdio.h>

 

int main() {

    float units, billAmount;

 

    // Input total units consumed

    printf("Enter total units consumed: ");

    scanf("%f", &units);

 

    billAmount = 0.0;

 

    // Slab calculation

    if (units <= 100) {

        billAmount = units * 1.50;

    }

    else if (units <= 200) {

        billAmount = 100 * 1.50 + (units - 100) * 2.50;

    }

    else if (units <= 300) {

        billAmount = 100 * 1.50 + 100 * 2.50 + (units - 200) * 4.00;

    }

    else {

        billAmount = 100 * 1.50 + 100 * 2.50 + 100 * 4.00 + (units - 300) * 5.00;

    }

 

    // Optional fixed charge

    billAmount += 50;  // e.g., fixed meter charge

 

    printf("\n----------------------------\n");

    printf("Electricity Bill\n");

    printf("Units Consumed: %.2f\n", units);

    printf("Total Amount  : ₹ %.2f\n", billAmount);

    printf("----------------------------\n");

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter total units consumed: 80

----------------------------
Electricity Bill
Units Consumed: 80.00
Total Amount  : ₹ 170.00
----------------------------


OUTPUT 2 :
Enter total units consumed: 250

----------------------------
Electricity Bill
Units Consumed: 250.00
Total Amount  : ₹ 650.00
----------------------------

OUTPUT 3 :
Enter total units consumed: 400

----------------------------
Electricity Bill
Units Consumed: 400.00
Total Amount  : ₹ 1050.00
----------------------------


Explanation

  1. The user enters the total units consumed.
  2. The program applies slab rates step by step:
    • First 100 units → ₹1.50/unit
    • Next 100 units → ₹2.50/unit
    • Next 100 units → ₹4.00/unit
    • Above 300 units → ₹5.00/unit
  3. A fixed charge (₹50 here) is added to the total.
  4. The final bill amount is displayed.