1
0

funds4.c 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* funds4.c -- passing an array of structures to a function */
  2. #include <stdio.h>
  3. #define FUNDLEN 50
  4. #define N 2
  5. struct funds {
  6. char bank[FUNDLEN];
  7. double bankfund;
  8. char save[FUNDLEN];
  9. double savefund;
  10. };
  11. double sum(const struct funds money[], int n);
  12. int main(void)
  13. {
  14. struct funds jones[N] = {
  15. {
  16. "Garlic-Melon Bank",
  17. 4032.27,
  18. "Lucky's Savings and Loan",
  19. 8543.94
  20. },
  21. {
  22. "Honest Jack's Bank",
  23. 3620.88,
  24. "Party Time Savings",
  25. 3802.91
  26. }
  27. };
  28. printf("The Joneses have a total of $%.2f.\n",
  29. sum(jones,N));
  30. return 0;
  31. }
  32. double sum(const struct funds money[], int n)
  33. {
  34. double total;
  35. int i;
  36. for (i = 0, total = 0; i < n; i++)
  37. total += money[i].bankfund + money[i].savefund;
  38. return(total);
  39. }