Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int i,j=0,code,amt, key,lines=0;
- int id[i],stock[i],k=0;
- char name[i][20],product[100];
- float price[i],sum;
- float total=0;
- char ipname[j][20],ch;
- int quantity[j];
- float ipprice[j];
- float ipsub[j];
- FILE*fp1;
- fp1=fopen("Fruit.txt","r");
- if(fp1==NULL)
- {
- printf("ERROR in opening filen");
- return 1;
- }
- else
- {
- while((ch=getc(fp1))!=EOF)
- {
- if(ch=='n')
- lines++;
- }
- }
- fclose(fp1);
- fp1=fopen("Fruit.txt","r");
- if(fp1==NULL){
- printf("ERROR in opening filen");
- return 1;
- }
- else
- {
- for(i=0;i<lines;i++){
- fgets(product,sizeof(product),fp1);
- id[i]=atoi(strtok(product,","));
- strcpy(name[i],strtok(NULL,","));
- price[i]=atof(strtok(NULL,","));
- stock[i]=atoi(strtok(NULL,"n"));
- }
- }
- fclose(fp1);
- printf("=============================================================n");
- for(i=0;i<lines;i++)
- {
- printf("%d:%-10st",i+1,name[i]);
- }
- printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
- printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
- do{
- k=0;
- if(j>0)
- {
- system("cls");
- }
- if(j>0)
- {
- printf("=============================================================n");
- for(i=0;i<lines;i++)
- {
- printf("%d:%-10st",i+1,name[i]);
- }
- printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
- printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
- for(k=0;k<j;k++)
- {
- printf("%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
- }
- }
- sum=0;
- amt=0;
- printf("nProduct code:");
- scanf("%d",&code);
- i=code-1;
- printf("Quantity:");
- scanf("%d",&amt);
- system("cls");
- sum=price[i]*amt;
- total=total+sum;
- ipprice[j]=price[i];
- strcpy(ipname[j],name[i]);
- quantity[j]=amt;
- ipsub[j]=sum;
- printf("=============================================================n");
- for(i=0;i<lines;i++){
- printf("%d:%-10st",i+1,name[i]);
- }
- printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
- printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
- for(k=0;k<=j;k++)
- {
- printf("%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
- }
- printf("%d",j);
- printf("nPress ESC on keyboard to finalize the bill or Press any key continue...n");
- key=_getch();
- if(key!=27)
- {
- j++;
- }
- }while(key!=27);
- printf("%d",j);
- printf("n%.2fn",total);
- FILE *fp2;
- fp2=fopen("receipt.txt","w");
- if(fp1==NULL)
- {
- printf("ERROR in opening filen");
- return 1;
- }
- time_t now;
- time(&now);
- fprintf(fp2,"Bear Hill Fruit StationnBukit Beruang, MelakanPhone: 06-2523344n=========================nnDate:%s", ctime (&now));
- fprintf(fp2,"nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
- fprintf(fp2,"%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
- for(k=0;k<=j;k++)
- {
- fprintf(fp2,"%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
- }
- fclose(fp2);
- return 0;
- }
- 18156,Apple,1.49,73
- 45776,Aprikot,1.59,23
- 73191,Avocado,2.49,63
- 72829,Banana,2.99,27
- 74084,Blueberry,5.49,36
- 79800,Coconut,3.49,80
- 16611,Grape,8.99,42
- 62690,Grapefruit,2.19,34
- 47089,Guava,4.99,42
- 70412,Jackfruit,19.99,29
- 44640,Kiwifruit,2.15,38
- 94768,Lemon,0.99,42
- 86240,Mango,3.99,62
- 78697,Orange,1.69,23
- 74470,Papaya,4.49,23
- 23959,Pear,2.49,36
- 78862,Pineapple,2.99,71
- 82943,Pomegranate,4.35,19
- 56180,Pomelo,12.99,72
- 67712,Starfruit,2.79,59
- 33974,Strawberry,13.99,31
- 12354,dildo,29.99,4
- 45584,Watermelon,6.88,21
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement