POP Lab Manual

Program 3

Develop a program to calculate Electricity Bill based on units consumed. The electricity board charges different rates for different usage slabs with minimum meter charge and surcharge for high consumption bills.
Charging Structure:
First 200 units: ₹0.80 per unit
Next 100 units (201-300): ₹0.90 per unit
Beyond 300 units: ₹1.00 per unit
Minimum Meter Charge: ₹100
Surcharge: 15% if total > ₹400

Algorithm

  1. Initialize: Start the program and declare variables for name, units, charge, and total
  2. Input Name: Read the user's name as a string
  3. Input Units: Read the number of units consumed as integer
  4. Calculate Charge: Apply slab-based pricing:
    • If units ≤ 200: charge = units × 0.80
    • If units ≤ 300: charge = 200×0.80 + (units-200)×0.90
    • If units > 300: charge = 200×0.80 + 100×0.90 + (units-300)×1.00
  5. Add Meter Charge: Add minimum ₹100 meter charge to the calculated amount
  6. Apply Surcharge: If total > ₹400, add 15% surcharge
  7. Display Output: Print user name, units consumed, and total charges
  8. Terminate: Stop the program

Flowchart

START
Input Name
Input Units
Calculate Slab Charges
Add Meter Charge
Check Surcharge
Display Bill
STOP

Code

#include <stdio.h>


int main() {
    char name[50];
    int units;
    float charge, total;

    // Input
    printf("Enter user name: ");
    scanf("%s", name);
    printf("Enter units consumed: ");
    scanf("%d", &units);

    // Calculate charge based on slabs
    if (units <= 200)
        charge = units * 0.80;
    else if (units <= 300)
        charge = 200 * 0.80 + (units - 200) * 0.90;
    else
        charge = 200 * 0.80 + 100 * 0.90 + (units - 300) * 1.00;

    // Add minimum meter charge
    total = charge + 100;

    // Apply surcharge if bill exceeds 400
    if (total > 400)
        total += total * 0.15;

    // Output
    printf("\nElectricity Bill\n");
    printf("Name: %s\n", name);
    printf("Units Consumed: %d\n", units);
    printf("Total Charges: Rs %.2f\n", total);

    return 0;
}

Output


// Example 1 - Low Usage (within first slab)
Enter user name: John
Enter units consumed: 150

Electricity Bill
Name: John
Units Consumed: 150
Total Charges: Rs 220.00

// Example 2 - Medium Usage (second slab)
Enter user name: Alice
Enter units consumed: 250

Electricity Bill
Name: Alice
Units Consumed: 250
Total Charges: Rs 305.00

// Example 3 - High Usage (third slab)
Enter user name: Bob
Enter units consumed: 350

Electricity Bill
Name: Bob
Units Consumed: 350
Total Charges: Rs 368.00

// Example 4 - High Bill with Surcharge
Enter user name: Sarah
Enter units consumed: 450

Electricity Bill
Name: Sarah
Units Consumed: 450
Total Charges: Rs 552.00

          
Comments

Replay !

0 Comments

Share Your Thoughts

Please enter your name
Please enter a valid email
Password must be at least 6 characters
Please enter your comment
Email Verification Required
We've sent a 6-digit verification code to . Please enter the code below to verify your email address.
Email Verified Successfully!
Your email has been verified. Would you like to proceed with posting your comment?

Type "YES" to confirm and post your comment, or click Cancel to skip posting.