Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Implement a structure for Transaction where you store the date of the transaction (day, month and year), amount (integer) and currency (char array of 3 chars). (10 points)
  2.  
  3. Write a main function where you read an integer N (max 500) and then read data for N transactions (each in new line in the following format: dd/mm/yyyy amount currency). (10 points)
  4.  
  5. Example:
  6.  
  7. 18/03/2016 310 MKD
  8. Print on the SO all the transactions with currency MKD that have amount greater then 1000 and were completed in the period from 01.01.2013 to 31.12.2015. (15 points)
  9.  
  10. Print the total amount of these transactions. (5 points)
  11.  
  12. For the printing format see the output of the first test sample.
  13. ---------------------------------------------------------------------------------------------------------------------------------------
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18.  
  19. typedef struct Transaction
  20. {
  21. int day;
  22. int month;
  23. int year;
  24. int ammount;
  25. char currency[3];
  26. }Transaction;
  27.  
  28. void function(int n)
  29. {
  30. int i;
  31. Transaction t[500];
  32. for(i=0; i<n;i++)
  33. {
  34. scanf("%2d/%2d/%4d %d %3s",&t[i].day,&t[i].month,&t[i].year,&t[i].ammount,&t[i].currency[3]);
  35.  
  36. }
  37. int j,sum=0;
  38. for(j=0;j<n;j++)
  39. {
  40. if(strcmp(t[j].currency,"MKD")&&t[j].ammount>1000 && (t[j].year<2013 || t[j].year>2015)==0)
  41. {
  42. sum+=t[j].ammount;
  43. printf("%d. %02d/%02d/%d %d %s\n",j,t[j].day,t[j].month,t[j].year,t[j].ammount,"MKD");
  44. }
  45. }
  46. printf("Total: %d %s",sum,"MKD");
  47.  
  48. }
  49.  
  50. int main()
  51. {
  52. int n;
  53. scanf("%d",&n);
  54. Transaction p;
  55. function(n);
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement