solve this question and show answer step by step A car dealership has 10 salespe
ID: 3778508 • Letter: S
Question
solve this question and show answer step by step 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: int cars[10]; Write a program to save the number of cars sold by each salesperson in the array named cars. 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.Explanation / Answer
Here is the code for you:
#include <iostream>
using namespace std;
int main()
{
int cars[10];
//Save the number of cars sold by each salesperson in the array named cars.
for(int i = 0; i < 10; i++)
{
cout<<"Enter the cars sold by sales person #"<<i+1<<": ";
cin>>cars[i];
}
//Output the total number of cars sold at the entire dealership.
int totalCarsSold = 0;
for(int i = 0; i < 10; i++)
totalCarsSold += cars[i];
//Which sales person sold the most cars.
int salesPerson = 0;
for(int i = 0; i < 10; i++)
if(cars[i] > cars[salesPerson])
salesPerson = i;
cout<<"The salesperson #"<<salesPerson+1<<" sold the most cars."<<endl;
//How many cars the best salesperson sold.
cout<<"The best salesperson sold "<<cars[salesPerson]<<" cars."<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.