C program to calculate the total electricity bill

Previous
Next

Conditions for calculation:

  • Up to 199 units Rs. 1.20/unit
  • From 200 to 400 units Rs. 1.50/unit
  • From 400 to 600 units Rs. 1.80/unit
  • For unit above 600 Rs. 2.00/unit
  • An additional surcharge of 15% is added to the bill.
#include <stdio.h>
int main()
{
	int unit;
	float amt, total_amt, sur_charge=0.0;
	
	printf("Enter total units consumed: ");
	scanf("%d", &unit);
	
	if(unit <= 50)
	{
		amt = unit * 1.20;
	}
	else if(unit <= 150)
	{
		amt = 25 + ((unit-50) * 1.50);
	}
	else if(unit <= 250)
	{
		amt = 100 + ((unit-150) * 1.80);
	}
	else
	{
		amt = 220 + ((unit-250) * 2.00);
	}
	
	if(unit > 400)
	{
		sur_charge = amt * 0.15;
	}
	total_amt  = amt + sur_charge;
	
	printf("Electricity Bill = Rs. %.2f", total_amt);
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form