Program to Generate the Electricity Bill

Started by thiruvasagamani, Sep 22, 2008, 10:52 AM

Previous topic - Next topic

thiruvasagamani

Generate electricity bill ,inputs meter number,customer name,prevous reading,present reading,type c1 for resident,type 2 for commercial,units = pres- prev readings,surcharge 10/-

i. if unit is first 100(0-99) cost is 3/- per unit
ii. next 100(100-199) units cost is 3.50/- per unit
iii. next 200 (200-399)units cost is 4/- per unit
iv. next 300 (400-699) units cost is 4.50 per unit
v. above 700 units cost is 5/- per unit

Program :

#include <stdio.h>
#include <conio.h>
main()
{
int mno,type,units,k;
long prev,pres;
char cname[20];
float cost;
clrscr();
printf("enter meter number \n");
scanf("%d",&mno);
printf("enter customer name\n");
fflush(stdin);
gets(cname);// flushes the \n in cname before storing a string in cname
printf("enetr prev & pres reading\n");
scanf(" %ld%ld",&prev,&pres);
printf("enter 1- residential, 2- commercial \n");
scanf("%d",&type);
units= abs(pres - prev);
switch(type)
{
case 1 :// residential
{
k = units / 100;
switch(k)
{
case 0 :
{
cost = units * 3.00;// units beween 0-99
break;//goes out inner switch
}
case 1 :
{
cost= 100 * 3.00 + (units-100)*3.5;
break;//units between 100-199
}
case 2 :
case 3 :
{
cost=100*3.00 + 100*3.50+(units-200)*4.00;
break;//units between 200-399
}
case 4 :
case 5 :
case 6 :
{
cost =100*3.00+100*3.50+200*4.00+(units-400)*4.50;
break;//units between 400to700
}
default :
{
cost=100*3.00+100*3.50+200*4.00+300*4.50+(units-700)*5.00
break;//units above 700,control goes out from inner switch
}//end of default
} //end of inner switch
break;//residential case 1 ends after this control goes out from outer switch
}
case 2 :
{
cost = units *5.00;
break;//control goes out from outer switch
}
}//end of outer switch
printf("bill amount = %.2f",cost+10);
getch();
}
Thiruvasakamani Karnan