Arrays

Hello, so I need help with this question on arrays. Can anyone explain how to write the code? Thank you so much.

Here's the question:

A car dealership has 10 salespeople. The dealership keeps track of the number of cars sold by each salesperson each month and reports it to management. The management then takes that data and assigns a number 1 – 10 to each salesperson.

The following statement declares an array to store the number of cars sold by each salesperson (it means that salesperson #1 sold 7 cars, salesperson #2 sold 3 cars etc):

int cars[10] = {7, 3, 6, 0, 14, 8, 1, 2, 9, 8};

Output
1) the total number of cars sold at the entire dealership,
2) which salesperson sold the most cars (Salesperson #1, Salesperson #2, etc.), and
3) how many cars that best salesperson sold.
Hello igamekiller,

You may want to start with this: http://www.cplusplus.com/doc/tutorial/arrays/

You have shown a good start with the cars array. If you are not stuck with that name I would consider changing it to "carsSold" to better explain what it is for.

I would most likely us a second array of std::strings for the sales people. Theif you sort the "carsSold" array include the other array for sales people so that they would match.

I, along with many others, are not in the habit of writing your code for you. Put something together and post it. Point out where you are having problems or what you do not understand and we can go fro there.

Hard to point you in the right direction when I do not know what you do know.

Hope that helps,

Andy
closed account (NCRLwA7f)
Hello,

Assuming that maybe you have read the link provided by Handy Andy

you will also need to do a few loop or functions (if you are doing functions now)

so for your output:

1. You need to make a function or a loop that adds all the values in the array together to get the total number of cars sold.
so something like cars[i] where i is the number of each location in the array from 0-9. make a loop that sums up the value of the array locations ex. sum = sum + cars[i];

2. you need to run a loop that compares each array value to each other you can do this with a loop, pretty much start from cars[0] and compare cars[1] - cars[9] with cars [0] then bump cars[0] up to cars[1] and start again, hint, use a loop inside a loop.

3. for this, I don't know how you have named your sales people but you can use the array location as the name for example cars[0] 0+1 = 1 salesperson 1
for cars[5] 5+1= would be salesperson 6. etc. So whatever array location has the largest value then that location is the bigger seller. From your data that is array location cars[4] = salesperson 5.
Topic archived. No new replies allowed.