Write a C program to generate electricity bill.
Program:
#include <stdio.h>
int main() {
int units;
float bill = 0;
// Input customer details and units consumed
printf("Enter electricity units consumed: ");
scanf("%d", &units);
// Bill calculation based on slab rates
if (units <= 100) {
bill = units * 1.5;
} else if (units <= 200) {
bill = (100 * 1.5) + ((units - 100) * 2.0);
} else if (units <= 300) {
bill = (100 * 1.5) + (100 * 2.0) + ((units - 200) * 3.0);
} else {
bill = (100 * 1.5) + (100 * 2.0) + (100 * 3.0) + ((units - 300) * 5.0);
}
// Adding a fixed meter charge (optional)
float meterCharge = 50.0;
float totalBill = bill + meterCharge;
// Output
printf("\n------ Electricity Bill ------\n");
printf("Units Consumed : %d\n", units);
printf("Energy Charges : ₹%.2f\n", bill);
printf("Meter Charges : ₹%.2f\n", meterCharge);
printf("Total Bill : ₹%.2f\n", totalBill);
printf("------------------------------\n");
return 0;
}
Comments
Post a Comment