Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

A shopkeeper wants to have a general program for his personal computer that will prepare bills for each customer as and when he sells goods of them

Posted By: Vemados Fischer     Category: C Programming     Views: 8083

A shopkeeper wants to have a general program for his personal computer that will prepare bills for each customer as and when he sells goods to them. His idea is that as soon as the customer purchases-some goods from his shop, he will supply the description, unit price and the quantity purchased for each item, as input to the computer. He wants that with this information the computer should print each item along
with its unit price, quantity purchased and the total
price. Finally, the computer should also print the
total cost of all the items purchased by the customer.
Assuming that a sentinel value of zero is used for the
quantity purchased field in the trailer record, Write
a program using structures/file to do this job.

Code for A shopkeeper wants to have a general program for his personal computer that will prepare bills for each customer as and when he sells goods of them in C Programming

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define SIZE 30
struct purchase
{
    char pur_desc[SIZE];
    int pur_unit;
    int pur_quantity;
    int pur_total;
};
void main()
{

          FILE *fp,*fout;
          char *filename;
          int grnd_total=0;
          struct purchase p1;
          int flag=0;
          p1.pur_quantity=99;
          p1.pur_total=0;
          clrscr();

          fp=fopen("input11.txt","w");

          if(fp==NULL)
          {
            printf("\n THE FILE CANNOT BE OPENED");
            exit(getch());
          }

          printf("\n ENTER 0 FOR THE QUANTITY TO TERMINATE......");
          while(p1.pur_quantity!=0)
          {
             flushall();
             printf("\n ENTER THE DESCRIPTION OF THE ITEM ::");
             scanf("%[^\n]",p1.pur_desc);
             flushall();
             printf("\n ENTER THE UNIT PRICE OF THE ITEM::");
             scanf("%d",&p1.pur_unit);
             flushall();
             printf("\n ENTER THE QUANTITY OF THE ITEM::");
             scanf("%u",&p1.pur_quantity);
             p1.pur_total=p1.pur_unit*p1.pur_quantity;
             fprintf(fp,"%s %d %u %d\n",p1.pur_desc,p1.pur_unit,p1.pur_quantity,p1.pur_total);
          }
          clrscr();
          fclose(fp);
          fp=fopen("input11.txt","r");
          fout=fopen("output11.txt","w");
          fprintf(fout,"\n THE INFORMATION OF THE BUYER IS AS FOLLOWS::");
          fprintf(fout,"\n DESCRIPION\tUNIT PRICE\tQUANTITY\tTOTAL");
          while(fscanf(fp,"%s %d %u %d",p1.pur_desc,&p1.pur_unit,&p1.pur_quantity,&p1.pur_total)!=EOF)
          {
           if(p1.pur_quantity!=0)
           {
             flag=1;
             fprintf(fout,"\n %s\t\t    %d\t           %u\t         %d",p1.pur_desc,p1.pur_unit,p1.pur_quantity,p1.pur_total);
             grnd_total=grnd_total+p1.pur_total;
           }
          }
          fclose(fp);
          if(flag==0)
          {
             fprintf(fout,"\n THERE IS NO RECORD IN THE FILE");
             exit(getch());
          }
          else
          {
              fprintf(fout,"\n THE GRAND TOTAL===\t\t\t        %d",grnd_total);
              getch();
          }
}



*********************INPUT****************************************
rice 10 10 100
tea 70 2 140
df 0 0 0


*********************OUTPUT****************************************
 THE INFORMATION OF THE BUYER IS AS FOLLOWS::
 DESCRIPION    UNIT PRICE    QUANTITY    TOTAL
 rice            10               10             100
 tea            70               2             140
 THE GRAND TOTAL===                    240


  
Share: 



Vemados Fischer
Vemados Fischer author of A shopkeeper wants to have a general program for his personal computer that will prepare bills for each customer as and when he sells goods of them is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!