Skip to content

Commit

Permalink
13 | 8-9 | sharafat
Browse files Browse the repository at this point in the history
  • Loading branch information
SharafatKarim committed Aug 17, 2023
1 parent 57b87cc commit 896c1c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions solutions/sharafat/13/8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>

struct Product
{
int code;
float cost;
int quantity;
};

int main()
{
FILE *fp;
fp = fopen("products.txt", "w");
struct Product products[5];
for (int i = 0; i < 5; i++)
{
printf("\nEnter product code: ");
scanf("%d", &products[i].code);
printf("Enter product cost: ");
scanf("%f", &products[i].cost);
printf("Enter product quantity: ");
scanf("%d", &products[i].quantity);
fprintf(fp, "%d %f %d\n", products[i].code, products[i].cost, products[i].quantity);
}
fclose(fp);
return 0;
}
17 changes: 17 additions & 0 deletions solutions/sharafat/13/9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

int main()
{
FILE *fp;
fp = fopen("products.txt", "r");
float sum = 0;
while (feof(fp) == 0)
{
float temp;
fscanf(fp, "%*d %f %*d ", &temp);
sum += temp;
}
fclose(fp);
printf("Total cost: %f\n", sum);
return 0;
}

0 comments on commit 896c1c7

Please sign in to comment.