Write a program that asks the user to enter the names of three salesmen. The pro
ID: 3866187 • Letter: W
Question
Write a program that asks the user to enter the names of three salesmen. The program should then accept the sales produced for salesman for each quarter of the year. Display the name, and the total sales amount, of each salesman. Name your program Lab11_Exercise1.cpp. Your program should have at least three functions: Your main, a second function that reads in the salesman name and sales amounts for the quarters, and a third function that displays the results. Do not use any global variables. You will need to pass data to the functions as parameters.Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main( )
{
string names[ 3 ];
double sales[ 3 ][ 4 ],total=0;
for(int i=0 ; i<3 ; i++)
{
count << "enter the name of the salesman " <<i + 1 << ": ";
cin >> names[ i ];
cout << "now enter in the sales for each quarter for " << names[ i ] << endl;
for(int j=0;j < 4; j++)
{
cout << "enter the data for quarter "<< j +1 << " : ";
cin >> sales[ i ][ j ];
}
cout << endl ;
}
cout << endl;
double max;
string name;
int i;
for(int j=0; j < 4; j++)
{
max=sales[ 0 ][ j ];
for(i=0; i< 3 ; i++)
{
if(max < sales[ i ][ j ])
{
max=sales[ i ][ j ];
name=names[ i ];
}
}
cout << " salesman" << name << " had the highest sale for the quarter " << j+1 << "with $" << max << ".00" << endl;
}
cout << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.