# Array of counters?

Page 1 of 1

## 9 Replies - 13571 Views - Last Post: 28 December 2010 - 08:23 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=207316&amp;s=10dc8bf2a6ab858099ad1718cd71e98e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Hayaa

Reputation: 0
• Posts: 5
• Joined: 28-December 10

# Array of counters?

Posted 28 December 2010 - 07:24 AM

Hi ...

can you tell me please where I can use the array in this Question ?

Use 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 receive \$200 plus 9 percent of \$5000, or 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):

I solve it with out using array, because I don't understand the question clear ...
my code ..

```#include<iostream>
using namespace std;

int main()
{
int earned;
int i=0;
const int size=8;
while(i<size)
{
int grossSales;
cout<<"Enter the Gross sales for this week: \n";
cin>>grossSales;
earned=((grossSales*9)/100)+200;
cout<<"The sales person earned this week in range: \n";

if(earned>=200 && earned<300)
cout<<"\$200-\$299"<<endl;

if(earned>=300 && earned<400)
cout<<"\$300-\$499"<<endl;

if(earned>=400 && earned<500)
cout<<"\$400-\$599"<<endl;

if(earned>=500 && earned<600)
cout<<"\$500-\$699"<<endl;

if(earned>=600 && earned<700)
cout<<"\$600-\$799"<<endl;

if(earned>=700 && earned<800)
cout<<"\$700-\$899"<<endl;

if(earned>=800 && earned<900)
cout<<"\$800-\$999"<<endl;

if(earned>=1000)
cout<<"\$1000 and over"<<endl;
i++;
}
return 0;
}

```

Is This A Good Question/Topic? 0

## Replies To: Array of counters?

### #2 janotte

• code > sword

Reputation: 991
• Posts: 5,141
• Joined: 28-September 06

## Re: Array of counters?

Posted 28 December 2010 - 07:32 AM

Let's break it down.
You are being asked to use a 1D array of counters
What do you think that means?
Spell it out for us.

EDIT
I looked more closely at your code.
Your 'solution' deals with a 'salesperson' but the question is about 'salespeople'.
Singular vs plural.
Perhaps focussing on that bit of the requirements would make it clearer to you that you have misunderstood what you are being asked to do.

This post has been edited by janotte: 28 December 2010 - 07:40 AM

### #3 Hayaa

Reputation: 0
• Posts: 5
• Joined: 28-December 10

## Re: Array of counters?

Posted 28 December 2010 - 07:42 AM

I don't know may be counting the earned for salesperson ...

really I don't know I think alot about it ,but there is no idea ...

### #4 janotte

• code > sword

Reputation: 991
• Posts: 5,141
• Joined: 28-September 06

## Re: Array of counters?

Posted 28 December 2010 - 07:43 AM

See my (too late) edit above.
You are thinking in the singular.
The challenge is in the plural.
Try reading the requirements out aloud slowly. You aren't understanding what you are being asked to do.
When I get confused reading things aloud helps me understand things better.

Reputation: 31
• Posts: 139
• Joined: 01-October 10

## Re: Array of counters?

Posted 28 December 2010 - 07:51 AM

I would guess English is not your native language. Just as janotte pointed out. A hint:

Quote

Write a program (using an array of counters)that determines how many of the salespeople earned salaries in each of the following ranges

Btw, usually in this kinda of range problems, we use if-else structure.

```if   (earned>=200 && earned<300)
cout<<"\$200-\$299"<<endl;
else if(earned>=300 && earned<400)
cout<<"\$300-\$499"<<endl;
//continue

```

### #6 Hayaa

Reputation: 0
• Posts: 5
• Joined: 28-December 10

## Re: Array of counters?

Posted 28 December 2010 - 07:59 AM

Declare an array that I put the values and calculate the earned then compare the value with the range , then determined the range !?

Reputation: 31
• Posts: 139
• Joined: 01-October 10

## Re: Array of counters?

Posted 28 December 2010 - 08:07 AM

Ah hahaha.

In my opinion, it wants the number of salesperson for each range stored in array. Maybe for an int array named counter and initialized by 0, for range 200<salary<300 the number of salesperson that get salary in that range is put inside counter[0]. Then range 300<salary<400 the number of salesperson that get salary in that range is put inside counter[1]. and so on. The increment can be done easily maybe using counter[0]++;

That should be quite comprehensible.

 tell me if I help him too much. >.>;

This post has been edited by shad0wk1: 28 December 2010 - 08:08 AM

### #8 janotte

• code > sword

Reputation: 991
• Posts: 5,141
• Joined: 28-September 06

## Re: Array of counters?

Posted 28 December 2010 - 08:12 AM

Seems like good advice and well given for the little my opinion is worth.

### #9 Hayaa

Reputation: 0
• Posts: 5
• Joined: 28-December 10

## Re: Array of counters?

Posted 28 December 2010 - 08:13 AM

Ahha ...

the array counting how many salespeople in each range earned..

that mean if there are two salespeople earned 200-299\$ then increment two in subscript for range 200-299\$ ...

### #10 Hayaa

Reputation: 0
• Posts: 5
• Joined: 28-December 10

## Re: Array of counters?

Posted 28 December 2010 - 08:23 AM