Now, I am converting the arrays to pointers. Hopefully I don't need to start a new thread. Please tell me if I do. When I compile, I get this error:
warning C4700: uninitialized local variable 'total' used
I am going over my code again and again and don't understand. I am calling the initialization function. If I change it from:
to this:
Code:
init_total(*total);
the compile again fails.
I'm sure it's something simple I am missing. Here's my code:
Code:
void init_total(double *t);
void report(double *s, char *n[]);
main()
{
double *total;
char *name[] = {"Steve Zahn", "Sarah Palin", "Eva Menedez", "Morley Safer", "Pete Rose"};
int cnum;
double pay;
char ch;
init_total(total);
do
{
printf("\nEnter your employee number (1-5): ");
scanf("%d%*c", &cnum);
printf("\nEnter amount of paycheck: ");
scanf("%lf%*c", &pay);
*(total+cnum) += pay;
printf("\nDo more (Y/N): ");
scanf("%c%*c", &ch);
ch = toupper(ch);
}
while (ch != 'N');
report(total, name);
return 0;
}
void report(double *s, char *n[])
{
int i;
printf("\nEmployee\t\t\tTotal Sales\n");
printf("-------\t\t-----------\n");
for (i = 1; i < 6 ; i++)
printf("%s\t\t\t%.2lf\n", *(n+i-1), *(s+i));
}
void init_total(double *t)
{
int i;
for (i=0; i < 6; i++)
*(t+i) = 0;
}