#include <ctype.h>
#include <stdio.h>
#define MAX_TRANSACTIONS 10
struct items {
double price;
int quantity;
double markup;
double total_price;
int total_sales;
};
void getnum(char *, const char *, void *);
struct items costs[MAX_TRANSACTIONS];
int trans;
double profit;
int main()
{
struct items *p;
char buffer[512];
char prompt;
do {
fputs("\n\tBUSINESS CALC SOFTWARE\n\n\n\tHow many transactions do you want? : ", stdout);
do {
getnum(buffer, "%d", &trans);
if(trans > MAX_TRANSACTIONS) {
fputs("\n\t\t(No transactions beyond 10)\n\n\tEnter transactions : ", stdout);
continue;
}
break;
} while(1);
profit = 0;
for(p = costs; p < &costs[trans]; ++p) {
fputs("\n\n\tEnter item price : ", stdout);
getnum(buffer, "%lf", &p->price);
fputs("\n\tEnter item quantity : ", stdout);
getnum(buffer, "%d", &p->quantity);
fputs("\n\tEnter markup : ", stdout);
getnum(buffer, "%lf", &p->markup);
p->total_price = (p->price + p->markup) * p->quantity;
p->total_sales += p->total_price;
p->markup *= p->quantity;
printf("\n\n\tTotal item price : %.2lf\n\n\n\t", p->total_price
);
profit += p->markup;
}
printf("\n\tTotal sales\t: %d", p->total_sales
);
printf("\n\tProfit\t\t: %.2lf\n\n", profit
);
fputs("\n\nDo you want another transaction? <y,n> ", stdout);
getnum(buffer, "%c", &prompt);
prompt = (isupper(prompt) ? tolower(prompt) : prompt);
} while(prompt == 'y');
return 0;
}
void getnum(char *buff, const char *format, void *ptr)
{
fgets(buff, sizeof buff, stdin);
sscanf(buff, format, ptr);
}