1. #include <ctype.h>
  2. #include <stdio.h>
  3.  
  4. #define MAX_TRANSACTIONS 10
  5.  
  6. struct items {
  7. double price;
  8. int quantity;
  9. double markup;
  10. double total_price;
  11. int total_sales;
  12. };
  13.  
  14. void getnum(char *, const char *, void *);
  15.  
  16. struct items costs[MAX_TRANSACTIONS];
  17.  
  18. int trans;
  19.  
  20. double profit;
  21.  
  22. int main()
  23. {
  24. struct items *p;
  25. char buffer[512];
  26. char prompt;
  27.  
  28. do {
  29. fputs("\n\tBUSINESS CALC SOFTWARE\n\n\n\tHow many transactions do you want? : ", stdout);
  30. do {
  31. getnum(buffer, "%d", &trans);
  32. if(trans > MAX_TRANSACTIONS) {
  33. fputs("\n\t\t(No transactions beyond 10)\n\n\tEnter transactions : ", stdout);
  34. continue;
  35. }
  36. break;
  37. } while(1);
  38. profit = 0;
  39. for(p = costs; p < &costs[trans]; ++p) {
  40. fputs("\n\n\tEnter item price : ", stdout);
  41. getnum(buffer, "%lf", &p->price);
  42. fputs("\n\tEnter item quantity : ", stdout);
  43. getnum(buffer, "%d", &p->quantity);
  44. fputs("\n\tEnter markup : ", stdout);
  45. getnum(buffer, "%lf", &p->markup);
  46. p->total_price = (p->price + p->markup) * p->quantity;
  47. p->total_sales += p->total_price;
  48. p->markup *= p->quantity;
  49. printf("\n\n\tTotal item price : %.2lf\n\n\n\t", p->total_price);
  50. profit += p->markup;
  51. }
  52. printf("\n\tTotal sales\t: %d", p->total_sales);
  53. printf("\n\tProfit\t\t: %.2lf\n\n", profit);
  54. fputs("\n\nDo you want another transaction? <y,n> ", stdout);
  55. getnum(buffer, "%c", &prompt);
  56. prompt = (isupper(prompt) ? tolower(prompt) : prompt);
  57. } while(prompt == 'y');
  58. return 0;
  59. }
  60.  
  61. void getnum(char *buff, const char *format, void *ptr)
  62. {
  63. fgets(buff, sizeof buff, stdin);
  64. sscanf(buff, format, ptr);
  65. }
  66.