display the index number of an array

I am trying to get the salesman number to output so I can identify the salesman who sold the most cars. I assumed I would be able to output the element of the array but when I run all I get is a hex output..

I am wanting to know what i did incorrectly in lines 46-50 to output to line 63.

Thank you for all your help!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <fstream>

// statement that allows the use of outputs without std:: prefix
using namespace std;

//create array cars with componenets
void display(int cars[10]);

//calculate total number sold for the month
int sold(int numsold[])

{
	int total = numsold[0];
	for (int i = 0; i < 10; i++)
	{
		total = total + numsold[i];
	}
	return total;
}

// calculate the most sold cars for the month
int mostSold(int sold[])
{
	int biggest = 0;
	for (int i = 0; i < 10; i++)
	{
		if (sold[i] > biggest)
		{
			biggest = sold[i];

		}
	}
	return biggest;
}

//calculate the index number for the array to identify the salesperson
int maxCars(int sold[], int i)
{
	return max_element(sold, sold + i) - sold;
	
}

//main function
int main()
{
	int cars[10];

	for (int i = 0; i < 10; i++)
	{
		cout << "\nEnter the number of cars sold by salesperson " << i + 1 << " this month: " << endl;
		cin >> cars[i];
	}
	
	cout << "The salesperson who sold the most was number: " << maxCars << endl;
	cout << "Total cars sold this month: " << sold(cars) << endl;
	cout << "The salesperson who sold the most was " << mostSold(cars) << " cars" << endl;

	system("pause");
	return 0;
}

// output the salesman who sold the most cars
void display(int cars[])
{
	cout << "The salesman is: " << endl;
	for (int i = 0; i < 10; ++i)
	{
		cout << "salesman " << i + 1 << ": " << cars[i] << endl;
	}
}
Line 60: You do not call the function. Instead you provide the pointer. To call the function:

cout << "The salesperson who sold the most was number: " << maxCars(cars, 10) << endl;
Thank you! I appreciate the quick response and help!
Topic archived. No new replies allowed.