Untitled
unknown
plain_text
a year ago
1.7 kB
8
Indexable
#include <stdio.h>
int main() {
int consumerNumber, meterNumber, previousReading, currentReading, totalUnits;
char consumerName[50];
float billAmount = 0.0;
// Input details
printf("Enter Consumer Number: ");
scanf("%d", &consumerNumber);
printf("Enter Consumer Name: ");
scanf("%s", consumerName);
printf("Enter Meter Number: ");
scanf("%d", &meterNumber);
printf("Enter Previous Meter Reading: ");
scanf("%d", &previousReading);
printf("Enter Current Meter Reading: ");
scanf("%d", ¤tReading);
// Calculate total units consumed
totalUnits = currentReading - previousReading;
// Calculate bill amount based on units consumed
if (totalUnits <= 100) {
billAmount = totalUnits * 2.00;
} else if (totalUnits <= 200) {
billAmount = 100 * 2.00 + (totalUnits - 100) * 3.00;
} else if (totalUnits <= 300) {
billAmount = 100 * 2.00 + 100 * 3.00 + (totalUnits - 200) * 4.50;
} else if (totalUnits <= 500) {
billAmount = 100 * 2.00 + 100 * 3.00 + 100 * 4.50 + (totalUnits - 300) * 5.50;
} else {
billAmount = 100 * 2.00 + 100 * 3.00 + 100 * 4.50 + 200 * 5.50 + (totalUnits - 500) * 7.00;
}
// Display the bill
printf("\nElectric Bill\n");
printf("Consumer Number: %d\n", consumerNumber);
printf("Consumer Name: %s\n", consumerName);
printf("Meter Number: %d\n", meterNumber);
printf("Previous Meter Reading: %d\n", previousReading);
printf("Current Meter Reading: %d\n", currentReading);
printf("Total Units Consumed: %d\n", totalUnits);
printf("Total Bill Amount: %.2f Rupees\n", billAmount);
return 0;
}
Editor is loading...
Leave a Comment