Sunday, August 2, 2009

C++ help needed please. Can you tell me how to fix it? thanks?

Use a one-dimensional array to solve the following problem:


A company pays its salespeople on a commission basis.


The salespeople each 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):


$200$299


$300$399


$400$499


$500$599


$600$699


$700$799


$800$899


$900$999


$1000 and over


I have


# include %26lt;iostream%26gt;


using std::cin;


using std::cout;


using std::endl;


int main()


{ int gross, pay, frequency[10]={0};


cout%26lt;%26lt;"Enter salesperson's gross sales in dollars (-1 to end): "%26lt;%26lt;endl;


cin%26gt;%26gt;gross;


pay=200+.09*gross;


while ( gross!= -1)


{int y=(pay-200)/100;


frequency[y]++;


** I will continue on the details**

C++ help needed please. Can you tell me how to fix it? thanks?
Of course, you set y = (pay-200)/100. If you do the math, that means pay = 200 + (.09*20000) = 2000. So pay = 2000. Alright so y = (2000 - 200)/100 = 18. Your array frequency only goes to [10]. So you're writing over memory that isn't yours. Hence, the error. You can only go from frenquency[0]-[10]. Not to [18].

augustifolia

No comments:

Post a Comment