Answer to Question #302043 in C for Suvedhaa

Question #302043

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

Input :

Gopinath

150

Output :

Customer Name: Gopinath

Sub Charge: 37.50

Total Charge: 987.50


1
Expert's answer
2022-02-24T12:19:13-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS