Steps:
1. Create an array of ints of size 9 (for 9 salary brackets). Initialize it to zero.
2. Take user input to determine how many employees we have.
3. Create a 'for' loop, which runs once for each employee. In the loop ask for their gross sales. Calculate 9%, add that to 200, and increment the appropriate element of the counter array.
4. Loop through each bracket of salaries and display the value of the appropriate counter.
Simple.
Note: When trying to determine what bracket a particular salary falls under, you could do it the simple way and add a bunch of 'if' statements. Even simpler though, would be to divide the salary by 100 (keeping everything as integers), and switching on the result. Look at how the brackets are set up:
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.
If you earnt anything from $800 to $899, dividing that number by 100, and taking the result as an integer (no decimals), gives you 8. Thus we can use the following code:
Code:
switch (Salary/100)
{
case 2:
Counters[0]++; //Increment the counter for that bracket
break;
case 3:
Counters[1]++; //Increment the counter
break;
//etc
As you can see, the Counters[n]++; statement will simply be repeated over and over. Also observe that the index used is always 2 less than the value of the 'case' statement. Thus we can shorten that code like so:
Code:
Counters[((int)Salary/100)-2]++;
The '(int)' is needed to remove the decimals resulting from the division.
I hope this has helped.