Define a structure for electricity board, the structure members customer name, unit consumed, sub charge and total charge. Implement the C program to calculate charges of the following rates for the energy consume,
Number of Units Cost per Unit
· For the first 200 units Rs. 5 per unit
· For the next 100 units Rs. 8 per unit
· For the next and above 300 units Rs. 10 per unit
The users are charged a minimum of Rs. 200/- as meter charge, and then an additional surcharge of 5% of total amount is charged. Read the customer names and number of units consumed as input and display the customer name, sub charges and total charge
#include <stdio.h>
struct electricity_board {
char *customer_name;
int unit_consumed;
int sub_charge;
int total_charge;
};
int calc_charges(int charge) {
if (charge <= 200) {
return 5 * (charge);
} else if (charge <= 300) {
return 8 * (charge - 200) + calc_cahrges(200);
} else if (cahrge <= 600) {
return 10 * (charge - 300) + calc_charges(300);
} return 0.05 * (charge);
}
int main() {
struct electricity_board board;
scanf("%c", board.customer_name);
scanf("%d", board.unit_consumed);
scanf("%d", board.sub_charge);
scanf("%d", board.total_charge);
printf("%d", calc_charges(board.total_charge));
return 0;
}
Comments
Leave a comment