upsidedown

electricity bill

Aug 16th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2. void main()
  3. {
  4.     float a,cno,bill;
  5.     char nm[50],add[50],ch;
  6.     FILE *f1,*f2;
  7.     f1=fopen("in1.txt","r");
  8.     if(f1==NULL)
  9.         printf("file cannot be opened\n");
  10.     f2=fopen("out1.txt","w");
  11.     if(f2==NULL)
  12.         printf("file cannot be opened\n");
  13.     do
  14.     {
  15.         fscanf(f1,"%s %f %s %f",nm,&cno,add,&a);
  16.         if(a>200)
  17.             bill=300+((a-200)*3);
  18.         else
  19.             if(a>100)
  20.                 bill=100+((a-100)*2);
  21.             else
  22.                 bill=a;
  23.             fprintf(f2,"%s\t%.2f\t%s\t%.2f\tRs%.2f\n",nm,cno,add,a,bill);
  24.     }while((ch=getc(f1))!=EOF);
  25.     fclose(f1);
  26.     fclose(f2);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment