Advertisement
Guest User

ZD 2

a guest
Jan 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. struct towar {
  5.     char nazwa[30];
  6.     int przecena;
  7.     double ilosc;
  8.     double cena;
  9. };
  10. double przecena();
  11. int main()
  12. {
  13.     double a;
  14.     a=przecena();
  15.     return 0;
  16. }
  17. double przecena()
  18. {
  19.     FILE *plik = fopen("magazyn.txt", "r+b");
  20.     struct towar t;
  21.     double proc=0, wartosc=0;
  22.     if(plik==NULL)
  23.     {
  24.         printf("blad pliku");
  25.         exit(1);
  26.     }
  27.     while(fread(&t, sizeof(struct towar), 1, plik) == 1)
  28.     {
  29.         proc=t.przecena/100;
  30.         proc=1-proc;
  31.         t.cena*=proc;
  32.         wartosc+=t.cena*t.ilosc;
  33.     }
  34.     fclose(plik);
  35.     return wartosc;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement