An electric company bases its charges on two rates, customers are charged P25.00 per kilowatt-hour for the first 300 kilowatt-hours used in a month and P30.00 each for all kilowatt-hours used thereafter. Compute for the amount due from a customer after reading the kilowatt-hours used. Assume that there are 100 records of customers.
In C:
#include <stdio.h>
#define RATE1 25.0
#define RATE2 35.0
#define THRESHOLD 300
#define N_CUSTOMERS 100
int main() {
double amount;
double charge;
double total_charge=0.0;
for (int i=0; i<N_CUSTOMERS; i++) {
printf("Enter amout consumed by customer %d: ", i+1);
scanf("%lf", &amount);
if (amount < THRESHOLD) {
charge = amount * RATE1;
}
else {
charge = THRESHOLD * RATE1 + (amount - THRESHOLD) * RATE2;
}
total_charge += charge;
}
printf("Total charge is P%.2f\n", total_charge);
return 0;
}
In Python
total_charge = 0
for i in range(1, 101):
amount = float(input(f'Enter amout consumed by customer {i}: '))
if amount < 300:
charge = amount * 25
else:
charge = 300 * 25 + (amount - 300) * 35
total_charge += charge
print(f'Total charge is P{total_charge:.2f}')
Comments
Leave a comment