Thursday, 8 September 2011

Calculate Electricity Bill with if-else condition



Calculate Electricity Bill with if-else condition
<=100 Rs.4/units
> 100 and <=300 Rs.4.50/units
>300 and <=500 Rs.4.75/units
>500 Rs.5/units

#include<stdio.h>
#include<conio.h>
void main ()
{
int unit, total;
clrscr ();
printf("Enter Total Units:");
scanf ("%d", &unit);
if (unit<=100)
{
total=unit*4;
}
else if (unit>100 && unit<=300)
{
total=unit*4.5;
}
else if (unit >300 && unit<=500)
{
total=unit*4.75;
}
else
{
total=unit*5;
}
printf("Total: %d", total);
getch ();
}


Method 2:(Coded by: Manpreet Singh Dhindsa, Patiala)

#include<stdio.h>
#include<conio.h>
void main()
{
int units;
float total_bill;
clrscr();
printf("Enter the no. of units");
scanf("%d",&units);
if(units <= 100)
total_bill = units * 4;
else if(units <= 300)
total_bill = units * 4.5;
else if(units <= 500)
total_bill = units * 4.75;
else
total_bill = units * 5;
printf("the bill to be paid is = %f", total_bill);
getch();
}





Question by: Simi Sandhu @ C Programming Facebook Page


No comments:

Post a Comment