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.
Algorithm
- Initialize: Start the program and declare variables for name, units, charge, and total
- Input Name: Read the user's name as a string
- Input Units: Read the number of units consumed as integer
- 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
- Add Meter Charge: Add minimum ₹100 meter charge to the calculated amount
- Apply Surcharge: If total > ₹400, add 15% surcharge
- Display Output: Print user name, units consumed, and total charges
- 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;
}
Replay !
Share Your Thoughts