Program below determines how many of the salespeople earned salaries in each of the following ranges.
- $200-299
- $300-399
- $400-499
- $500-599
- $600-699
- $700-799
- $800-899
- $900-999
- $1000 and over
/* title: salesComission coder: aeriqusyairi date: Jan25 2012 */ #include<stdio.h> #define SALESPERSON 20 #define RANGE 9 void calculateSalary( int b[] ); void calculateRange( const int b[], int a[] ); int main(){ int gross[ SALESPERSON ] = { 3000, 4000, 7000, 8000, 10000, 30000, 500, 6000, 4000, 7000, 5000, 1500, 400, 15000, 2000, 50000, 3000, 40000, 5000, 10000 }; int salaryRange[ RANGE ] = { 0 }; int i, j, k; calculateSalary( gross ); calculateRange( gross, salaryRange ); for(i = 0, j = 200, k = 299 ; i < RANGE; i++, j += 100, k += 100 ){ if(k < 1000) printf("%d salesperson earn salary between %d and %d.\n", salaryRange[ i ], j, k ); else printf("%d salesperson earn salary of %d and over.\n", salaryRange[ i ], j ); } system("pause"); return 0; } void calculateSalary( int b[] ){ int i; for(i = 0; i < SALESPERSON; i++){ b[ i ] *= 0.09; b[ i ] += 200; } } void calculateRange( const int b[], int a[] ){ int i; for(i = 0; i < SALESPERSON; i++ ){ if( b[i] >= 200 && b[ i ] < 300 ) a[ 0 ]++; else if( b[i] >= 300 && b[ i ] < 400 ) a[ 1 ]++; else if( b[i] >= 400 && b[ i ] < 500 ) a[ 2 ]++; else if( b[i] >= 500 && b[ i ] < 600 ) a[ 3 ]++; else if( b[i] >= 600 && b[ i ] < 700 ) a[ 4 ]++; else if( b[i] >= 700 && b[ i ] < 800 ) a[ 5 ]++; else if( b[i] >= 800 && b[ i ] < 900 ) a[ 6 ]++; else if( b[i] >= 900 && b[ i ] < 1000 ) a[ 7 ]++; else if( b[i] >= 1000 ) a[ 8 ]++; } }
No comments:
Post a Comment