Advertisement
mehedi1

Project Ta1.c

Sep 11th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main() {
  4.     FILE *fp;
  5.     fp=fopen("input.txt","w");
  6.     if(fp==NULL) {
  7.         printf("Error!! Opening FIle\n");
  8.         return 1;
  9.     }
  10.  
  11.     int n, p;
  12.     char s[25];
  13.     printf("Enter The Total Number of Items: \n");
  14.     scanf("%d",&n);
  15.     fprintf(fp, "%d\n", n);
  16.     printf("Enter Item Name & Price: \n");
  17.     for(int i=1;i<=n;++i) {
  18.         scanf("%s %d",s, &p);
  19.         fprintf(fp, "%s %d\n", s,p);
  20.     }
  21.     fclose(fp);
  22.  
  23.     fp=fopen("input.txt","r");
  24.     int num;
  25.     rewind(fp);
  26.     fscanf(fp, "%d", &num);
  27.  
  28.     char str[100][20];
  29.     int price[100];
  30.     for(int i=1;i<=num;++i) {
  31.         fscanf(fp, "%s %d",str[i],&price[i]);
  32.     }
  33.     fclose(fp);
  34.  
  35.     for(int i=1;i<=num;++i) {
  36.         printf("\t\t\t\t\t%d. %s = %d\n", i, str[i], price[i]);
  37.     }
  38.  
  39.     int quantity[25];
  40.     for(int i=1;i<=num;++i) {
  41.         printf("Enter The Quantity of - %s: ", str[i]);
  42.         scanf("%d",&quantity[i]);
  43.     }
  44.     int total = 0;
  45.     for(int i=1;i<=num;++i) {
  46.         total += price[i] * quantity[i];
  47.     }
  48.     printf("Total: %d\n", total);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement