Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople receive $200 perweek pluse 9 percent of their gross sales for that week. For example, a salesperson that grosses $3000 in sales in a week receives $200 plus 9 percent of $3000, or a total of $470. Write a C program (using an array of counters)that determines how many of the salespeople earned salaries in each of the following ranges(assume that each salesperson's salary is truncated to an integer amonut).
I'm not having people to do my homework, I try to write it myself, the program works, the only problem I have is that I should only need array[8] not [9], but for some reason the -1 that user enter was count it to array number[8], so if I only have one salesperson that have make over $1000, my array counter [8] will print 2 instead of 1. So I set the array to [9] to take that -1, but didn't output to the screen.
Can anyone tell me what did I do wrong in my code?
thank you........
int main(void)
{
int array[9];
int sale = 0;
float comm;
int i;
for(i=0; i<9;i++)
{
array[i]=0;
}
while(sale != -1)
{
printf("\nPlease enter employee gross sales enter -1 to quit: ");
scanf("%d", &sale);
comm =( sale*9/100) + 200;
if(comm >200 && sale!=-1)
{
printf("Employee Commission is $%.2f\n", comm);
}
if(comm>200 && comm <=299)
array[0]++;
else if(comm>=300 && comm<=399)
array[1]++;
else if(comm>=400 && comm<=499)
array[2]++;
else if(comm>=500 && comm<=599)
array[3]++;
else if(comm>=600 && comm<=699)
array[4]++;
else if(comm>=700 && comm<=700)
array[5]++;
else if(comm>=800 && comm<=899)
array[6]++;
else if(comm>=900 && comm<=999)
array[7]++;
else if(comm>1000)
array[8]++;
else
array[9];
}
printf("\nNumber of employees in the range of:\n\n");
printf("$200-299: %d\n", array[0]);
printf("$300-399: %d\n", array[1]);
printf("$400-499: %d\n", array[2]);
printf("$500-599: %d\n", array[3]);
printf("$600-699: %d\n", array[4]);
printf("$700-799: %d\n", array[5]);
printf("$800-899: %d\n", array[6]);
printf("$900-999: %d\n", array[7]);
printf("Over $1000: %d\n", array[8]);
return;
}