C Program to calculate the electricity bill for a domestic customer.


#include <stdio.h>
#include<conio.h>


void print_details(char *N,int n,int l,int c,int u,int a,int m)
{


   printf("\n Consumer name\t\t: %s\n"
      "\n Consumer number\t\t: %d\n"
      "\n Last meter reading\t: %d\n"
      "\n Current meter reading\t: %d\n"
      "\n No. of units consumed\t: %d\n"
      "\n Charge for electricity\t: %d\n"
      "\n Meter rent\t\t: %d\n"
      "\n Net Amount (Rs.)\t: %d\n",N,n,l,c,u,a,m,a+m);

}
void get_details(char *PN,int  *Pn,int *Pl,int *Pc)
{
   do
   {
      clrscr();
      puts("Enter the consumer name,Consumer number\tLast and current meeter reading");
      scanf("%s%d%d%d",PN,Pn,Pl,Pc);
   }while(*Pc<*Pl || *Pn<1);
}

void process_details(int u,int *Pa)
{
   if(u<=100)
      *Pa = u*0.5;
   else if(u<=200)
      *Pa=(100*0.5)+(u-100);
   else
      *Pa = (100*0.5)+100+((u-200)*1.5);

}



void main()
{
   char name[21];
   int num,last,current,amt,units,meter_rent=5;
   get_details(name,&num,&last,&current);
   units = current-last;
   process_details(units,&amt);
   print_details(name,num,last,current,units,amt,meter_rent);
   getch();

}