Advertisement
mehedi1

Untitled

Sep 11th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     FILE *fp;
  8.  
  9.     int n,p,num,ch;
  10.     char ope;
  11.  
  12.     char s[25],str[100][20];
  13.     int price[100];
  14.  
  15.     do
  16.     {
  17.         printf("\t\t\t\t\t\t\t   TAJAMHAL FOOD\t\t\n");
  18.         printf("Press 1 to entry item and Further process\nPress 2 to show item and Further process\n");
  19.  
  20.         scanf("%d",&ch);
  21.         printf("\n\n");
  22.         switch(ch)
  23.         {
  24.         case 1:
  25.         {
  26.             fp=fopen("input.txt","w");
  27.             if(fp==NULL)
  28.             {
  29.                 printf("Error!! Opening FIle\n");
  30.                 return 1;
  31.             }
  32.  
  33.             printf("Enter The Total Number of Items: \n");
  34.             scanf("%d",&n);
  35.             fprintf(fp, "%d\n", n);
  36.             printf("Enter Item Name & Price: \n");
  37.             for(int i=1; i<=n; ++i)
  38.             {
  39.                 scanf("%s %d",s, &p);
  40.                 fprintf(fp, "%s %d\n", s,p);
  41.             }
  42.             fclose(fp);
  43.  
  44.         }
  45.  
  46.         case 2:
  47.         {
  48.             fp=fopen("input.txt","r");
  49.  
  50.             rewind(fp);
  51.             fscanf(fp, "%d", &num);
  52.  
  53.  
  54.             for(int i=1; i<=num; ++i)
  55.             {
  56.                 fscanf(fp, "%s %d",str[i],&price[i]);
  57.             }
  58.             fclose(fp);
  59.  
  60.  
  61.     printf("\n\t\t\t\t\t\t\t    Cash Memo\t\t\n");
  62.     printf("\t\t\t\t\t\t*********************************\t\t\n");
  63.             for(int i=1; i<=num; ++i)
  64.             {
  65.                 printf("\t\t\t\t\t%d. %s = %d\n", i, str[i], price[i]);
  66.             }
  67.         }
  68.         printf("\n\n");
  69.         }
  70.  
  71.  
  72.         printf("Press 0 to End: \n");
  73.         int idx[25], quantity[25], total = 0, id;
  74.         for(id=1;;++id) {
  75.             scanf("%d",&idx[id]);
  76.             if(idx[id]==0) break;
  77.             scanf("%d",&quantity[id]);
  78.             total += price[idx[id]] * quantity[id];
  79.         }
  80.  
  81.         for(int j=1;j<id;++j) {
  82.             printf("%d %s %d %d\n", j, str[idx[j]], quantity[j], price[idx[j]] * quantity[j]);
  83.         }
  84.         printf("\n\n\n\tTotal money: %d\n", total);
  85.  
  86.         printf("\n\n\nDo You Want to Continue?\nPress y to Continue.\nAny other key to exit.\n");
  87.         getchar();
  88.         ope=getchar();
  89.         system("cls");
  90.     }
  91.     while(ope=='y');
  92.  
  93.  
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement