Write a ‘C’ program to calculate the electricity bill using if..elseif, as per the following details
Given the number of units consumed, unit charges are as follows:
i) For first 50 units Rs. 0.50/unit
ii) For next 100 units Rs. 0.75/unit
iii) For next 100 units Rs. 1.20/unit
iv) For unit above 250 Rs. 1.50/unit
Add fuel surcharge 20% and Govt. Tax 10% on bill to calculate the total bill.
#include<stdio.h>
#include<conio.h>
void main ( )
{
int unit;
float cost, fuel, tax;
clrscr ( );
printf ("\n Enter the number of unit consumed..:"); scanf ("%d",&unit);
if (unit <= 50)
{
cost = unit *.50;
}
else if (unit <= 150)
{
unit = unit - 50;
cost = 50 *.50 + unit * .75;
}
else if (unit <= 250)
{
unit = unit - 150;
cost = 50 * .50 + 100 *.75 + unit * 1.20;
}
else
{
unit = unit - 250;
cost = 50 * .50 + 100 * .75 + 100 * 1.20 + unit * 1.50;
}
fuel = cost * 20 / 100;
tax = cost * 10 / 100;
printf ("\n Gross amount = %.2f",cost);
printf ("\n Fuel charges = %.2f",fuel);
printf ("\n Tax = %.2f",tax);
printf ("\n_________________________\n");
printf ("\n Gross amount = %.2f",cost + fuel + tax);
getch( );
}
Click here to contact us.
No comments:
Post a Comment