954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

array help

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
{code}
#include
#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]);

}

ellas747
Newbie Poster
11 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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
#define SIZE 10

void chart (int p[], int r[]);
void 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]= (int)(200+.09*sales[i]);
}
printf("%7d%13d ", i,sales[i]);
chart(p, r);
}

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

{
int r[10]={0};
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 {
++ r[9];
}


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

}

prathys
Newbie Poster
5 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 
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 ***
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
vkiller
Newbie Poster
8 posts since Dec 2007
Reputation Points: 7
Solved Threads: 0
 
for( int i=0; i< <strong>14</strong>; i++)
{
   p[i]= (200+.09*sales[i]);
}
<strong>printf("%7d%13d ", i, sales[i]);</strong>

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

<strong>int range[SIZE]={0};</strong>

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

chart(p<strong>[]</strong>, <strong>r[]</strong>)

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

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

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

invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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.

invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You