# Salary Range Calculator help please!! =(

• 04-20-2006
bambino
Salary Range Calculator help please!! =(
I do not know what I am doing wrong, but I can not figure this out for the life of me. Anyone know what is wrong with my program? I am trying to get it to input the sales for the week, then calculate 9% of that plus 200 dollars for each person, and output it on the chart, but for some reason the chart sticks all the people in the over 1000 dollar category. Im so confused =(

Code:

```int main()    //start program { //declare and initialize array int rangeSales[9] = {0}; //declare and initialize variables int salary = 200; int grossSales = 0; int commission = 0;   //Enter the gross sales for each salesperson   cout << "Enter the gross sales, enter -1 to stop: ";       cin >> grossSales;   cout << endl;   while(grossSales != -1)   {       commission = grossSales * .09;       salary = salary + commission;   if(salary >= 200 && salary <= 299)       rangeSales[0]++;   if(salary >= 300 && salary <= 399)       rangeSales[1]++;   if(salary >= 400 && salary <= 499)       rangeSales[2]++;   if(salary >= 500 && salary <= 599)       rangeSales[3]++;   if(salary >= 600 && salary <= 699)       rangeSales[4]++;   if(salary >= 700 && salary <= 799)       rangeSales[5]++;   if(salary >= 800 && salary <= 899)       rangeSales[6]++;   if(salary >= 900 && salary <= 999)       rangeSales[7]++;   if(salary >= 1000)       rangeSales[8]++;   //Enter the gross sales for each salesperson   cout << "Enter the gross sales, enter -1 to stop: ";       cin >> grossSales;   cout << endl;   } //end while //display the count for each salary range cout << "The count for \$200-\$299 range is: " << rangeSales[0] << endl; cout << "The count for \$300-\$399 range is: " << rangeSales[1] << endl; cout << "The count for \$400-\$499 range is: " << rangeSales[2] << endl; cout << "The count for \$500-\$599 range is: " << rangeSales[3] << endl; cout << "The count for \$600-\$699 range is: " << rangeSales[4] << endl; cout << "The count for \$700-\$799 range is: " << rangeSales[5] << endl; cout << "The count for \$800-\$899 range is: " << rangeSales[6] << endl; cout << "The count for \$900-\$999 range is: " << rangeSales[7] << endl; cout << "The count for over \$1000 range is: " << rangeSales[8] << endl; }```
• 04-20-2006
Cactus_Hugger
Hmm, can't get the behavior you describe, but a few notes:
* Make sure you've included iostream and have "using namespace std;"

Why do you have "salary = salary + commission;" ? First, it's redundant: "salary += commission", but furthermore, the salary for a salesperson will depend on the order I enter them, which makes no sense. Why does the sales of one salesperson get added to the last salesperson? (If so, I wanna be the last one entered in!) What I think you want is:
Code:

`salary = 200 + commission;`
But I could be wrong.

Finally, your if()s can be greatly simplified. Only one of those is going to prove true, so take advantage of the keyword else:
Code:

```if(salary < 200) cout << "Negative commission?" << endl; else if(salary < 300) rangeSales[0]++; else if(salary < 400) rangeSales[1]++; //etc, etc. else rangeSales[8]++;```
• 04-20-2006
Bench82
The problem seems to be that you are constantly adding to your salary variable without resetting it for each employee - Unless the company awards money to the next employee based on the previous employee's sales, you probably want a constant which records the basic salary, to be used when determining the total pay.

Also - this is a style issue, but the name rangeSales[] is very confusing - you're recording the salary range, not the sales range.
• 04-20-2006
bambino
Quote:

Originally Posted by Cactus_Hugger
Why do you have "salary = salary + commission;" ? First, it's redundant: "salary += commission", but furthermore, the salary for a salesperson will depend on the order I enter them, which makes no sense. Why does the sales of one salesperson get added to the last salesperson? (If so, I wanna be the last one entered in!) What I think you want is:
Code:

`salary = 200 + commission;`
But I could be wrong.

OMG how could I have been so stupid

the reason i did that was because I set salary to 200 in the begining, but I didnt realize that I used the variable twice!!! :eek:

THANKS SO MUCH!