C++ coding problem everything was fine but when I run the program sales 1 name i
ID: 3573381 • Letter: C
Question
C++ coding problem
everything was fine but when I run the program sales 1 name is not print out
can you guys fixed the error for me?? here is my code
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//Function declarations
void getData(string names[],double sales[3][4]);
void calTotalSales(string names[],double sales[3][4]);
int main()
{
//Creating an string array of size 3
string names[3];
//Creating a double array
double sales[3][4];
//Calling the functions
getData(names,sales);
calTotalSales(names,sales);
return 0;
}
//Function implementation which will get the inputs entered by the user
void getData(string names[],double sales[3][4])
{
/* This for loop will get the names and sales
* in each quarters entered by the user and
* populate them into arrays
*/
for(int i=0;i<3;i++)
{
//Getting the name entered by the user
cout<<"Enter in the name of the salesman "<<i+1<<": ";
cin>>names[i];
//Getting the sales in each quarter entered by the user
cout<<"Now Enter in the sales for each quarter for "<<names[i]<<endl;
for(int j=0;j<4;j++)
{
cout<<"Enter in the data for the quarter "<<j+1<<": ";
cin>>sales[i][j];
}
cout<<endl;
}
}
/* Function implementation which will calculate
* and display the total sales made by each
* person in 4 quarters
*/
void calTotalSales(string names[],double sales[3][4])
{
//Declaring variable
double max;
string name;
int i;
/* This for loop will calculate each person
* total sales and display it one the console
*/
cout << setprecision(2) << fixed;
for(int j=0;j<4;j++)
{
//Calculating the total sales in 4 quarters
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 << endl;
}
}
Explanation / Answer
#include #include using namespace std; int main() { string names[3]; double sales[3][4], total = 0; for(int i = 0 ; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.