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.
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <fstream>
// statement that allows the use of outputs without std:: prefix
usingnamespace 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;
}
}