hozer

SlavaStructLab2

May 29th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. int main(void)
  8. {
  9.     struct date
  10.     {
  11.         int d, m, y;
  12.     };
  13.  
  14.     struct medt {
  15.         char name[64];
  16.         struct date release;
  17.         int count, term;
  18.         float price;
  19.     } *medts;
  20.  
  21.     struct date now;
  22.  
  23.     int n, i, j;
  24.     float overTermPrice = 0.0;
  25.  
  26.     printf("input n: "); scanf("%d", &n);
  27.     printf("input date (dd mm yyyy):"); scanf("%d %d %d", &now.d, &now.m, &now.y);
  28.     medts = (struct medt*)malloc(sizeof(*medts) * n);
  29.     fflush(stdin);
  30.  
  31.     for (i = 0; i < n; i++)
  32.     {
  33.         printf("Input name: "); gets(medts[i].name);
  34.         printf("Input price count: "); scanf("%f %d", &medts[i].price, &medts[i].count);
  35.         printf("input term (years): "); scanf("%d", &medts[i].term);
  36.         printf("input release date (dd mm yyyy): "); scanf("%d %d %d", &medts[i].release.d, &medts[i].release.m, &medts[i].release.y);
  37.         fflush(stdin);
  38.     }
  39.  
  40.     for (i = 0; i < n; i++)
  41.     {
  42.         if (medts[i].release.y + medts[i].term - now.y < 0)
  43.             overTermPrice += medts[i].price * medts[i].count;
  44.         else if (medts[i].release.y + medts[i].term - now.y == 0)
  45.             if (medts[i].release.m - now.m < 0)
  46.                 overTermPrice += medts[i].price * medts[i].count;
  47.             else if (medts[i].release.m - now.m == 0)
  48.                 if (medts[i].release.d - now.d < 0)
  49.                     overTermPrice += medts[i].price * medts[i].count;
  50.     }
  51.    
  52.  
  53.     printf("Sum = %f", overTermPrice);
  54.     free(medts);
  55.  
  56.     _getch();
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment