#include <stdio.h>
#include <string.h> // Required for string operations if you expand customer details
int main() {
int unit;
float amt, total_amt, sur_charge, rate_per_unit;
// Hardcoded customer details for the bill display
char customer_name[] = "John Doe";
int customer_id = 12345;
/* Input total units consumed from user */
printf("Enter total units consumed: ");
scanf("%d", &unit);
/* Calculate electricity bill according to given conditions (example rates) */
if (unit <= 50) {
rate_per_unit = 0.50;
amt = unit * rate_per_unit;
} else if (unit <= 150) {
rate_per_unit = 0.75;
// First 50 units at 0.50, remaining at 0.75
amt = (50 * 0.50) + ((unit - 50) * rate_per_unit);
} else if (unit <= 250) {
rate_per_unit = 1.20;
// First 50 at 0.50, next 100 at 0.75, remaining at 1.20
amt = (50 * 0.50) + (100 * 0.75) + ((unit - 150) * rate_per_unit);
} else {
rate_per_unit = 1.50;
// First 50 at 0.50, next 100 at 0.75, next 100 at 1.20, remaining at 1.50
amt = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + ((unit - 250) * rate_per_unit);
}
/* Add a 20% surcharge if the basic amount exceeds Rs. 400 */
if (amt > 400) {
sur_charge = amt * 0.20;
} else {
sur_charge = 0;
}
total_amt = amt + sur_charge;
/* Display the electricity bill */
printf("\n--- Electricity Bill ---\n");
printf("Customer IDNO: %d\n", customer_id);
printf("Customer Name: %s\n", customer_name);
printf("Unit Consumed: %d\n", unit);
printf("Amount Charges @Rs. %.2f per unit: %.2f\n", rate_per_unit, amt);
printf("Surcharge Amount: %.2f\n", sur_charge);
printf("Net Amount Paid By the Customer: %.2f\n", total_amt);
printf("--------------------------\n");
return 0;
}
Comments
Post a Comment