Hi everyone. First off, thanks for your help on my array problem last time. However, I now have a problem with my functions, in particular, passing my global arrays into functions. No matter what I do, I just can't get them to talk to each other. Thanks for your suggestions, Scarlet7. It helped clean up some of my code, but the function problem remains. I tried looking over tutorials and in my C book, but none of the solutions seem to work.
Code:
#define ZERO 0.0
#define COMMISSION_RATE 0.144
#define BONUS_COMM_RATE 0.188
#define TRUE 1
#define FALSE 0
#define HIGH_SALESPERSON 7
#define ARRAY_SIZ 75
#include <stdio.h>
int s_code[ARRAY_SIZ];
int c_code[ARRAY_SIZ];
double sale_amount[ARRAY_SIZ];
double sale_comm[ARRAY_SIZ];
int flag[ARRAY_SIZ];
void input_fun(int s_code[ARRAY_SIZ], int c_code[ARRAY_SIZ], double sale_amount[ARRAY_SIZ], int i);
void output_fun(int o, int number, int branch[]);
int sales_code();
int cust_code();
double sale();
void comm_report (double comm, int bonus);
void sale_error();
main()
{ int num_sales = 0;
double total_sales, total_comm;
int n = 0;
input_fun(s_code, c_code, sale_amount, n);
for (n = 0; n < num_sales; n++)
{
if (sale_amount[n] > 1450)
{
flag[n] = TRUE;
sale_comm[n] = (208.8 + ((sale_amount[n] - 1450) * BONUS_COMM_RATE));
}
else
{
flag[n] = FALSE;
sale_comm[n] = (sale_amount[n] * COMMISSION_RATE);
}
total_sales += sale_amount[n];
total_comm += sale_comm[n];
}
output_fun(n, num_sales, flag);
}
void
input_fun(int s_code[ARRAY_SIZ], int c_code[ARRAY_SIZ], double sale_amount[ARRAY_SIZ], int i)
{
int count;
s_code[i] = sales_code();
while (s_code[i] != ZERO)
{
if (s_code[i] <= HIGH_SALESPERSON && s_code[i] > ZERO)
{
c_code[i] = cust_code();
sale_amount[i] = sale();
count += 1;
i++;
s_code[i] = sales_code();
}
else
{
sale_error();
s_code[i] = sales_code();
}
}
return;
}
void
output_fun(int o, int number, int branch[])
{
printf("\n\n SALES REPORT");
printf("\n\nSP CUST SALE COMM");
for (o = 0; o < number; o++)
{
printf("\n%d %3d $%9.2lf", &s_code[o], &c_code[o], &sale_amount[o]);
if (branch[o] == TRUE)
{
printf("**");
}
else
{
printf(" ");
}
printf(" $%9.2lf", &sale_comm[o]);
}
return;
}
int
sales_code()
{
int sval;
printf("\n\nSalesperson code (1-7)(Enter 0 to quit): ");
scanf("%d", &sval);
return sval;
}
int
cust_code()
{
int cval;
printf("Customer code: ");
scanf("%d", &cval);
return cval;
}
double
sale()
{
double amount;
printf("Sale amount in dollars and cents: ");
scanf("%lf", &amount);
return amount;
}
void
sale_error()
{
printf("Salesperson code must be 1 to 7");
return;
}
When it prints, it prints out the first two lines, as it is a direct print command. The problem is that my statistics don't show up. I'm thinking that it's in my input function. Either way, I'm pulling my hair out over this.
I know the output function prototype is constructed much differently from the input function, but neither one seems to work and I'm at my wits end as to which one is closer to correct.
Thanks again in advance. I hope I don't come off as one looking for handouts, it's just that I'm very frustrated right now after pounding away at the code for so long.