i have this project to do for class. i get how the program works.here is the project:
Use a single subscript array and functions to solve the following problem. A company pays its salespeople on a commission basis. The salesperson receives $200 per week plus 9 percent of his/her gross sales for that week. For example; a salesperson whose gross sale is $3000 in a week receives $200 plus 9% of $3000, or a total of $470. Write a C program using arrays and function) that determines how many of the sales people earned salaries in the following ranges (assume that each salesperson’s salary is truncated to an integer amount):

  1. $200-$299
  2. $300-$399
  3. $400-$499
  4. $500-$599
  5. $600-$699
  6. $700-$799
  7. $800-$899
  8. $900-$999
  9. $1000-over

You can assume that the company has a sale force of 50 employees.

You out should include a histogram

I wrote this program but i stuck. i'm confused a whole lot. can anyone help me PLEASE.
thanks

#include <stdio.h>
#define SIZE 10

void chart (int p[], int r[]);
int main()
{
    int range[SIZE]={0};
    int sales[20]=
    { 267, 359, 468, 525, 678, 710, 856, 867, 920, 1067,
      254, 987, 1034, 875, 345, 765, 234, 500, 300, 490};
    int p[20];

    for( int i=0; i<14; i++)
    {
        p[i]= (200+.09*sales[i]);
    }
         printf("%7d%13d     ", i,sales[i]);
         chart(p[], r[])
return 0;
}

void chart ( int p[], int r[])

{
    for( int i= 0; i<14; i++)
    {
        if ( p[i] >0 && p[i] <200){
            ++ r[0];
    }
       else if (p[i] >=200 && p[i] <300){
        ++ r[1];
       }

       else if (p[i] >=300 && p[i] <400){
           ++ r[2];
       }
       else if (p[i] >=400 && p[i] <500){
           ++ r[3];
       }
       else if (p[i] >=500 && p[i] <600){
           ++ r[4];
       }
       else if (p[i] >=600 && p[i] <700){
           ++ r[5];
       }
       else if (p[i] >=700 && p[i] <800){
           ++ r[6];
       }
       else if (p[i] >=800 && p[i] <900){
           ++ r[7];
       }
       else if (p[i] >=900 && p[i] <1000){
           ++ r[8];
       }
       else if (p [i] >1000){
           ++ r[9];
       }


}
}
      for( int i=0; i<=size; i++)
      {
      printf("%7d%13d     ",i, r[i]);

  }

Edited 3 Years Ago by pyTony: fixed formating

i got ur code.i saw some mistakes in ur code.
First of all u r going to get the result in float.So u have to properly typecast where ever needed.

i have made some modifications in ur code.Now try this code.If this also dont work,send me the error messages you get.ok.have a nice time


#include <stdio.h>
#define SIZE 10

void chart (int p[], int r[]);
void int main()
{
int range={0};
int sales[20]=
{ 267, 359, 468, 525, 678, 710, 856, 867, 920, 1067,
254, 987, 1034, 875, 345, 765, 234, 500, 300, 490};
int p[20];

for( int i=0; i<14; i++)
{
p= (int)(200+.09*sales);
}
printf("%7d%13d ", i,sales);
chart(p, r);
}

void chart ( int p[], int r[])

{
int r[10]={0};
for( int i= 0; i<14; i++)
{
if ( p >0 && p <200)
{
++ r[0];
}
else if (p >=200 && p <300){
++ r[1];
}

else if (p >=300 && p <400){
++ r[2];
}
else if (p >=400 && p <500){
++ r[3];
}
else if (p >=500 && p <600){
++ r[4];
}
else if (p >=600 && p <700){
++ r[5];
}
else if (p >=700 && p <800){
++ r[6];
}
else if (p >=800 && p <900){
++ r[7];
}
else if (p >=900 && p <1000){
++ r[8];
}
else {
++ r[9];
}


}
}
for( int i=0; i<=size; i++)
{
printf("%7d%13d ",i, r);

}

i have made some modifications in ur code.Now try this code.If this also dont work,send me the error messages you get.ok.have a nice time

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
 test.c:
 Error E2176 test.c 5: Too many types in declaration
 Error E2188 test.c 13: Expression syntax in function main
 Error E2451 test.c 13: Undefined symbol 'i' in function main
 Error E2379 test.c 13: Statement missing ; in function main
 Error E2451 test.c 18: Undefined symbol 'r' in function main
 Warning W8070 test.c 19: Function should return a value in function main
 Warning W8004 test.c 19: 'sales' is assigned a value that is never used in function main
 Warning W8004 test.c 19: 'range' is assigned a value that is never used in function main
 Error E2238 test.c 24: Multiple declaration for 'r' in function chart
 Error E2188 test.c 25: Expression syntax in function chart
 Error E2451 test.c 25: Undefined symbol 'i' in function chart
 Error E2379 test.c 25: Statement missing ; in function chart
 Warning W8004 test.c 62: 'r' is assigned a value that is never used in function chart
 Warning W8057 test.c 62: Parameter 'p' is never used in function chart
 Warning W8057 test.c 62: Parameter 'r' is never used in function chart
 Error E2040 test.c 63: Declaration terminated incorrectly
 Error E2141 test.c 63: Declaration syntax error
 Error E2141 test.c 63: Declaration syntax error
 *** 12 errors in Compile ***
for( int i=0; i< [b]14[/b]; i++)
{
   p[i]= (200+.09*sales[i]);
}
[b]printf("%7d%13d ", i, sales[i]);[/b]

1) You have 20 data of salaries. However you only loop 14 times.
2) I think you mistakenly printf outside your loop.

[B]int range[SIZE]={0};[/B]

3) You seem to declare a variable that will never ever use.

chart(p[B][][/B], [B]r[][/B])

4) It is not how to pass array into function. It should be p not p[].
5) Why would you need to pass variable that you never touch?

void chart ( int p[], [B]int r[][/B])
{[B]
int r[10]={0};[/B]
for( int i= 0; i<[B]14[/B]; i++)

6) You declared r[] twice.
7) Again, you only run through 14 data of salaries.

Yeah, and this thread was 3 years old before assorted "chippies" came along with their "me too" responses.

Yeah, and this thread was 3 years old before assorted "chippies" came along with their "me too" responses.

Damnit... it was 3 years ago. I didn't know it was 3 years ago.

This article has been dead for over six months. Start a new discussion instead.