Write a C program to calculate Electricity bill.

Description:

You need to write a C program to calculate electricity bill using if-else statements.

Conditions:

  • For first 50 units – Rs. 3.50/unit
  • For next 100 units – Rs. 4.00/unit
  • For next 100 units – Rs. 5.20/unit
  • For units above 250 – Rs. 6.50/unit
  • You can use conditional statements.
#include<stdio.h>
int main()
{
	float bill, units;
	
	printf("Enter the units consumed=");
	scanf("%f",&units);
	
	if(units<=50 && units>=0)
	{
		bill=units*3.50;
		printf("Electricity Bill=%f Rupees",bill);
	}
	else if(units<=100 && units>50)
	{
		bill=50*3.50+(units-50)*4;
		printf("Electricity Bill=%f Rupees",bill);

	}
	else if(units<=250 && units>150)
	{
		bill=50*3.50+100*4+(units-150)*5.20;
		printf("Electricity Bill=%f Rupees",bill);

	}
	
	else if(units>250)
	{
		bill=50*3.50+100*4+100*5.20+(units-250)*6.50;
		printf("Electricity Bill=%f Rupees",bill);

	}
	else
	{
		printf("Please enter valid consumed units...");
	}
	return 0;
}
Tutorials Class - Output Window

Enter the units consumed=278.90
Electricity Bill=1282.84 Rupees


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.