Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7.  
  8. int main()
  9. {
  10. int i,j=0,code,amt, key,lines=0;
  11. int id[i],stock[i],k=0;
  12. char name[i][20],product[100];
  13. float price[i],sum;
  14. float total=0;
  15. char ipname[j][20],ch;
  16. int quantity[j];
  17. float ipprice[j];
  18. float ipsub[j];
  19.  
  20. FILE*fp1;
  21.  
  22. fp1=fopen("Fruit.txt","r");
  23. if(fp1==NULL)
  24. {
  25. printf("ERROR in opening filen");
  26. return 1;
  27. }
  28. else
  29. {
  30. while((ch=getc(fp1))!=EOF)
  31. {
  32. if(ch=='n')
  33. lines++;
  34. }
  35. }
  36. fclose(fp1);
  37.  
  38. fp1=fopen("Fruit.txt","r");
  39. if(fp1==NULL){
  40. printf("ERROR in opening filen");
  41. return 1;
  42. }
  43. else
  44. {
  45.  
  46. for(i=0;i<lines;i++){
  47. fgets(product,sizeof(product),fp1);
  48. id[i]=atoi(strtok(product,","));
  49. strcpy(name[i],strtok(NULL,","));
  50. price[i]=atof(strtok(NULL,","));
  51. stock[i]=atoi(strtok(NULL,"n"));
  52.  
  53. }
  54. }
  55. fclose(fp1);
  56.  
  57. printf("=============================================================n");
  58. for(i=0;i<lines;i++)
  59. {
  60. printf("%d:%-10st",i+1,name[i]);
  61. }
  62. printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
  63. printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
  64.  
  65. do{
  66. k=0;
  67. if(j>0)
  68. {
  69. system("cls");
  70. }
  71. if(j>0)
  72. {
  73. printf("=============================================================n");
  74. for(i=0;i<lines;i++)
  75. {
  76. printf("%d:%-10st",i+1,name[i]);
  77. }
  78. printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
  79. printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
  80. for(k=0;k<j;k++)
  81. {
  82. printf("%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
  83. }
  84. }
  85. sum=0;
  86. amt=0;
  87. printf("nProduct code:");
  88. scanf("%d",&code);
  89. i=code-1;
  90. printf("Quantity:");
  91. scanf("%d",&amt);
  92. system("cls");
  93. sum=price[i]*amt;
  94. total=total+sum;
  95. ipprice[j]=price[i];
  96. strcpy(ipname[j],name[i]);
  97. quantity[j]=amt;
  98. ipsub[j]=sum;
  99. printf("=============================================================n");
  100. for(i=0;i<lines;i++){
  101. printf("%d:%-10st",i+1,name[i]);
  102. }
  103. printf("nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
  104. printf("%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
  105. for(k=0;k<=j;k++)
  106. {
  107. printf("%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
  108. }
  109. printf("%d",j);
  110. printf("nPress ESC on keyboard to finalize the bill or Press any key continue...n");
  111. key=_getch();
  112. if(key!=27)
  113. {
  114. j++;
  115. }
  116. }while(key!=27);
  117. printf("%d",j);
  118.  
  119. printf("n%.2fn",total);
  120.  
  121. FILE *fp2;
  122. fp2=fopen("receipt.txt","w");
  123. if(fp1==NULL)
  124. {
  125. printf("ERROR in opening filen");
  126. return 1;
  127. }
  128. time_t now;
  129. time(&now);
  130. fprintf(fp2,"Bear Hill Fruit StationnBukit Beruang, MelakanPhone: 06-2523344n=========================nnDate:%s", ctime (&now));
  131. fprintf(fp2,"nn%-5s%-20s%-15s%-10s%sn","No.","Product","Price","Quantity","Subtotal");
  132. fprintf(fp2,"%-5s%-20s%-15s%-10s%sn","===","=======","=====","========","========");
  133. for(k=0;k<=j;k++)
  134. {
  135. fprintf(fp2,"%-5d%-20s%-15.2f%-10d%.2fn",k+1,ipname[k],ipprice[k],quantity[k],ipsub[k]);
  136. }
  137. fclose(fp2);
  138.  
  139.  
  140. return 0;
  141. }
  142.  
  143. 18156,Apple,1.49,73
  144. 45776,Aprikot,1.59,23
  145. 73191,Avocado,2.49,63
  146. 72829,Banana,2.99,27
  147. 74084,Blueberry,5.49,36
  148. 79800,Coconut,3.49,80
  149. 16611,Grape,8.99,42
  150. 62690,Grapefruit,2.19,34
  151. 47089,Guava,4.99,42
  152. 70412,Jackfruit,19.99,29
  153. 44640,Kiwifruit,2.15,38
  154. 94768,Lemon,0.99,42
  155. 86240,Mango,3.99,62
  156. 78697,Orange,1.69,23
  157. 74470,Papaya,4.49,23
  158. 23959,Pear,2.49,36
  159. 78862,Pineapple,2.99,71
  160. 82943,Pomegranate,4.35,19
  161. 56180,Pomelo,12.99,72
  162. 67712,Starfruit,2.79,59
  163. 33974,Strawberry,13.99,31
  164. 12354,dildo,29.99,4
  165. 45584,Watermelon,6.88,21
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement