I've lost my will and need some guidence, yes this is homework, i'm not going to lie about that. I know I could probably figure out how to get the answer she's wanting, but not with what she's provided as a code template below. I'm guessing that I need to get the weekly gross and then calculate the .9% of the gross and then add $200. I'm thinking that once I have this amount, I'll need to use an array to see where they fall on the money scale and then truncate all the others left in memory? I have till Friday to get this done and have stressed out so much, that i can't seem to get started again. Any advice? Please be gentile, i'm fragile! Thanks

Pete


Use a single-subscripted array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent of $5000, or a total of $650. Write a 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 amount):

a) $200 - $299
b) $300 - $399
c) $400 - $499
d) $500 - $599
e) $600 - $699
f) $700 - $799
g) $800 - $899
h) $900 - $999
i) $1000 and over

Your output should appear in the following format:

Enter employee gross sales ( -1 to end ) : 10000
Employee commission is $1100.00

Enter employee gross sales ( -1 to end ) : 4235
Employee commission is $581.15

Enter employee gross sales ( -1 to end ) : 600
Employee commission is $254.00

Enter employee gross sales ( -1 to end ) : 12500
Employee commission is $1325.00

Enter employee gross sales ( -1 to end ) : -1
Employees in the salary range:
$200 - $299 : 1
$300 - $399 : 0
$400 - $499 : 0
$500 - $599 : 1
$600 - $699 : 0
$700 - $799 : 0
$800 - $899 : 0
$900 - $999 : 0
over $1000 : 2



[Note: We will use one variable chart for this problem even though we will have three code blocks: main, wages and display. Use of these variables is required; however, depending upon how you design your solution, you may use more variables.]

#include <iostream>
   
  using std::cout;
  using std::cin;
  using std::endl;
  using std::ios;
   
  #include <iomanip>
   
  using std::setw;
  using std::setiosflags;
  using std::setprecision;
   
  //function prototypes
  void wages( int [] );                     // function to calculate each salesperson’s salary + commission
                                                  //   and to increment appropriate counter
  void display( const int [] );           // function to display the cumulative results in array of counters
   
  int main()           // main will not require any modification
  {
              //variable declarations
              int salaries [ 11 ] = { 0 }; // array of counters to track number of salespeople
                                                  //   in each salary range
   
              // calculate salaries and display results
              wages( salaries );
              display( salaries );
              
              return 0;
  } //end main
   
  
   void wages ( int money[] )           // function definition skeleton only
  {
              // variable declarations
              double   sales,                                       // gross sales for the week
                          commissionRate = 0.09,             // a percent of gross sales
                          salary,                                      // for current salesperson
                          // note: depending upon how you solve this, you may need more
   
   
   
   
              // input control loop here
              while (                          ) { 
   
   
   
   
   
   
   
   
   
   
              } // end while
  } // end wages
   
   
   
   
  void display ( const int dollars[] )             // function definition skeleton only
  {
              // variable declarations
              int index;                                   // array subscript variable
   
   
   
              for ( index = ?; index < ?; index++ ) {
   
   
              } // end for
   
   
   
  } // end display

I'm not looking for code, just needing help understanding what's needed. The template I provided is confusing to me as it's hard enough writing code let alone trying to use a template. I'm just trying to see if I'm understanding what the goal is.

I need to get the weekly gross and then calculate the .9% of the gross and then add $200. I'm thinking that once I have this amount, I'll need to use an array to see where they fall on the money scale and then truncate all the others left in memory?

Do the assignment one step at a time and it will be a lot easier. If you try to do it all at once you might wind up just getting more confused.

Start with function wages(). You know that you have to have a prompt "Enter employee gross sales ( -1 to end )" inside that while loop, and somehow you have to allow the user to type in a number into the double variable sales, which is already defined in the function. Once you get that you need to calculate the commission with is 9% of the sales. That's simple 2nd or 3d grade math -- employee commission is $200.00 plus (sales * commissionRate).

Get that all working then come back for more questions/answers.

I'm having a hard time with the loop "for( int i = 0; i < 5; ++i )"
I'm wanting (-1 to end).
As above, I'm saying go up to 5, but below, it's saying continue until you get -1. I tried to change it to -1, but then it just loops and loops.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <iomanip>

using std::setw;
using std::setiosflags;
using std::setprecision;

//function prototypes
void wages( int [] );        // function to calculate each salesperson's salary + commission
                //   and to increment appropriate counter
void display( const int [] );    // function to display the cumulative results in array of counters

int main()    // main will not require any modification
{
    double sales;
    double wages;
  
    cout << setprecision( 2 );

    for( int i = 0; i < 3; ++i  )  {             
   
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
   
       
        }            // end for
return 0;

} //end main

>>// main will not require any modification

you did not follow instructions. put main() back the way it was and add your code in the wages() function.

>> for( int i = 0; i < 3; ++i )
There is no limit to the number of salaries you can enter. So you are using the wrong kind of loop. I suggest using a do-while loop, something like this:

do
{
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
} while(sales >= 0);

I missed that, I think that's my stress level going up. I've made the changes back to the main and when I add the do while logic, i'm getting errors.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <iomanip>

using std::setw;
using std::setiosflags;
using std::setprecision;

//function prototypes
void wages( int [] );        // function to calculate each salesperson's salary + commission
                //   and to increment appropriate counter
void display( const int [] );    // function to display the cumulative results in array of counters

int main()    // main will not require any modification
{
    //variable declarations
    int salaries [ 11 ] = { 0 };    // array of counters to track number of salespeople
                //   in each salary range

    // calculate salaries and display results
    wages( salaries );
    display( salaries );

return 0;

} //end main


void wages ( int money[] )    // function definition skeleton only
{
    // variable declarations
    double     sales,                 // gross sales for the week
        commissionRate = 0.09,        // a percent of gross sales
        salary,                // for current salesperson
        // note: depending upon how you solve this, you may need more




    // input control loop here
do
{
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
} while(sales >= 0);
    
    } // end while
} // end wages

1. you need a semicolon after the declaraction of salary

2. count the number of closing braces in that function. You have one too many.

>>I think that's my stress level going up
Yup, that happens to all of us. When you get stressed out just get up and go have a cup of coffee or something. DO NOT drink alcohol -- it does more harm than good.

I think I do need to take a break, I've been looking at this function and it's still getting errors. says I'm missing a ";" I've added it removed it, rearanged it and still comes up... I think i'll go for a nap......

void wages ( int money[] )    // function definition skeleton only
{
    // variable declarations
    double     sales,                 // gross sales for the week
        commissionRate = 0.09,        // a percent of gross sales
        salary;                // for current salesperson
        // note: depending upon how you solve this, you may need more
 
 
 
 
    // input control loop here
do {
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;

while(sales >= 0);
} //end while    
   
    }// end wages
// input control loop here
do {
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
 
while(sales >= 0);
 } //end while should be before the while statement

Hmm... I think you're supposed to put the closing brace in a do...while loop before the while statement.

I tried that as well and get a different error:
assignment4.obj : error LNK2001: unresolved external symbol "void __cdecl display(int const * const)" (?display@@YAXQBH@Z)
Debug/project4.exe : fatal error LNK1120: 1 unresolved externals

that error means you have not coded the function. compare your program with the template your teacher gave you and you will see your code is missing that function.

That was it... I commented it out so I could get one thing working....
I'm thinking this below is where I need to set up my dollar amount array.

void display ( const int dollars[] )        // function definition skeleton only
{
    // variable declarations
//    int index;            // array subscript variable

//    for ( index = ?; index < ?; index++ ) {

//    } // end for



} // end display

I beleive I have my wages function set up and gathering the data needed. I'm looking at the display function to count how many employees are in each salary range.

My question is, don't I need a count = 0 and then I'm not sure how to put this together. Any suggestions? or articles I could look at that deal with what this needs to do? Thanks

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <iomanip>

using std::setw;
using std::setiosflags;
using std::setprecision;

//function prototypes
void wages( int [] );        // function to calculate each salesperson's salary + commission
                //   and to increment appropriate counter
void display( const int [] );    // function to display the cumulative results in array of counters

int main()    // main will not require any modification
{
    //variable declarations
    int salaries [ 11 ] = { 0 };    // array of counters to track number of salespeople
                //   in each salary range

    // calculate salaries and display results
    wages( salaries );
    display( salaries );

return 0;

} //end main

void wages ( int money[] )    // function definition skeleton only
{
    // variable declarations
    double sales,                 // gross sales for the week
           commissionRate = 0.09,        // a percent of gross sales
           salary;                // for current salesperson  
 
 
// input control loop herea
do {
        cout <<"Enter employee gross sales ( -1 to end )\n";
        cin >> sales;    //keep gross in keyboard buffer
        
        salary = ((sales *.09) + 200);    //calculate salary
        cout<< setw(3)<< "Employee commission is $" << setw(6)<< salary << endl;
        
        //cout<< setw(24)<< salary << endl; //verify calcutation
        
    //    commissionRate = salary * 0.09;
    //    cout << setw(24)<< commissionRate << endl;

} //end wage void

while(sales >= 0);     
    
} //end while


void display ( const int dollars[] )        // function definition skeleton only
{
    // variable declarations
//    int index;            // array subscript variable



//    for ( index = 0; index < salary; index++ ) {

//        if (salary >= 200 && salary <= 299)
//            s2++;
//        if (salary >= 300 && salary <= 399)
//            s3++;
//        if (salary >= 400 && salary <= 499)
//            s4++;
//        if (salary >= 500 && salary <= 599)
//            s5++;
//        if (salary >= 600 && salary <= 699)
//            s6++;
//        if (salary >= 700 && salary <= 799)
//            s7++;
//        if (salary >= 800 && salary <= 899)
//            s8++;
//        if (salary >= 900 && salary <= 999)
//            s9++;
//        if (salary >= 1000)
//            s10++;

//    } // end for



} // end display

you are not finished with the wages() function yet. The whole idea of that function is to populate the money[] array with the salary. After calculating salary you need to add it to the ith element of the money[] array. you will have to add an integer counter to keep track of the current row number in the array.

>>while(sales >= 0);
also add verification that the counter value (see above) does not exceed the number or rows in the array so that you can't add more sales numbers than there is room in the array.


>>for ( index = 0; index < salary; index++ ) {

No! not salary but the number of rows in the dollars array. I would add another parameter to the function that indicates the number of rows in the array because without it that function has no clue what it is.

This question has already been answered. Start a new discussion instead.