I am creating simple program to take input of an employee number (1-5) and how much their paycheck was. I loop until no more entries are desired. Then, I output their name (based on their employee number -1 matching the name array position) and their accumulated pay. Here is my code:
Code:
main()
{
double total[6];
char name[5][13] = {"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[cnum-1]);
return 0;
}
void report(double s[], char n[])
{
int i;
printf("\nEmployee\t\t\tTotal Pay\n");
printf("-------\t\t\t-----------\n");
for (i = 1; i < 6 ; i++)
printf("%s\t\t\t%.2lf\n", &n[i], s[i]);
}
Here is what my output should be, for example:
Code:
Employee Total Pay
------------- -------------
Steve Zahn 100.00
Sarah Palin 1234.56
Eva Menedez 222.22
Morley Safer 321.09
Pete Rose 7777.89
I am doing something wrong and not getting the right output. I am not getting the name array to display properly. It displays similar to this:
Code:
Employee Total Pay
------------- -------------
Steve Zahn 100.00
teve Zahn 1234.56
eve Zahn 222.22
ve Zahn 321.09
e Zahn 7777.89
Any help would be appreciated.