Taxidriver
Programmer
I've written a code that should accomplish this task:
There are 10 sellers, everyone has a code number (1-10).
The program accepts in input the code of the seller and how much the seller has earned, then it calculates the bonus that the company will pay to each seller according to their earnings. I used a pointer matrix to keep these information:
seller number, earnings, bonus.
The code works but for one thing, the compiler signalls errors in the first and second "else if". If I put the first "else if" between comments brackets the code works. But I really can't see the mistake! I'm sure it is something stupid but I can't figure out by myself.
There are 10 sellers, everyone has a code number (1-10).
The program accepts in input the code of the seller and how much the seller has earned, then it calculates the bonus that the company will pay to each seller according to their earnings. I used a pointer matrix to keep these information:
seller number, earnings, bonus.
The code works but for one thing, the compiler signalls errors in the first and second "else if". If I put the first "else if" between comments brackets the code works. But I really can't see the mistake! I'm sure it is something stupid but I can't figure out by myself.
Code:
#define maxnumber 10
#include <stdio.h>
#include <alloc.h>
#include <string.h>
void main()
{
int *seller[maxnumber], i, j, vendita, codice;
char numero[50];
/* initialization and pointer allocation */
vendita=0;
for (i=0; i <= maxnumber; ++i)
{ seller[i]=malloc(6);
*seller[i]=0;
*(seller[i]+1)=0;
*(seller[i]+2)=0; }
/* data introduction */
printf("\nIntroduce seller code\n");
while (strcmp(gets(numero),"z") !=0)
{
codice=atoi(numero);
*seller[codice]=codice;
printf("\nIntroduce earning, dollars:\n");
scanf("%10d", &vendita);
*(seller[codice]+1)+=vendita;
/* bonus calculating */
if (*(seller[codice]+1) < 100 )
*(seller[codice]+2)= *(seller[codice]+1)*5/100;
else if ((100 <= *(seller[codice]+1) &&
(*(seller[codice]+1) <= 200))
*(seller[codice]+2)= *(seller[codice]+1)*7.5/100;
else if ( *(seller[codice]+1) > 200)
*(seller[codice]+2) = *(seller[codice]+1)*10/100;
printf("\nIntroduce seller code\n");
gets(numero);
}
/* results */
printf("\n Seller earning bonus");
for (i=0 ; i < maxnumber; ++i)
printf("\n %3d %10d %10d", i+1, *(seller[i]+1), *(seller[i]+2));
}