December 9, 2024

C Program to Demonstrate the Electricity Meter Charge

Detailed Question: An electricity board charges the following rates for the use of electricity: for the first 200 units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs. 1 per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total amount is more than 400, then an additional surcharge of 15% of total amount is charged. Design and Develop a program to read the name of the user, number of units consumed and print out the charges.

We will understand the question and will come up with logic.
There are different parts in the question.
1: Get user input for the name, number of units consumed.
2: Calculate the amount for the unit consumed.
3: Meter charge of Rs. 100.
4: Get the total amount by adding the Amount for the unit consumed + Meter charge(Rs.100)
4: If the above amount is more than Rs.400, add additional surcharge of 15%.
5: Display the total amount.

#include <stdio.h>

float getAmount(int);

int main() {
   
   int units = 0;
   char name[100];
 
   printf("Enter Name\n");
   scanf("%s", name);

   printf("Enter meter reading\n");
   scanf("%d", &units);
    
   int meterCharge = 100;
   float amount = getAmount(units);     
   float totAmount = amount + meterCharge;
	
   if(totAmount >400){
	float additionalCharge =  totAmount * .15;
	totAmount = totAmount + additionalCharge;
   }
    printf("\n=============================\n");   
    printf("Name= %s",name);
    printf("\nTotal amount is: %.2f",totAmount);
    printf("\n");
	
   return 0;
}

float getAmount(int unit){
	
	float amount =0;
	
    if(unit <=200){
		amount = unit *0.8;
    }else if(unit >200 && unit <=300){
		//for the first 200 unit, charge is 80 Paisa per unit. 
        amount = 200 * 0.8;
		amount = amount + (unit-200)*0.9;
    }else{
		amount = 200 * 0.8;
		amount = amount + (100 * 0.9);
		amount = amount + (unit-300)*1;
    }		
    return amount;	
		
}	
	

Step 1 : Will create a separate function: getAmount . Will pass the unit consumed to this method. This method will calculate the amount for the unit consumed.
Step 2: Get the total amount by adding the above amount with meter charge.
Check if the above amount is more than 400 or not. I have used if condition. If the amount is more than 400, get the additional charge. additionalCharge = totAmount * .15; 15% is nothing but 0.15. Calculate the total amount.
Display the total amount.

Output is as shown below

2 thoughts on “C Program to Demonstrate the Electricity Meter Charge

  1. I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Fantastic work!

Leave a Reply

Your email address will not be published. Required fields are marked *