How can I display the sum of total from the input entered for each salesperson? This is in C++

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main()
{
// decalre variables
const int NUM_NAMES = 3;
const int NUM_SALES = 4;
string names[NUM_NAMES];
int sales[NUM_SALES];
// int *total;

// ask user to input names of salesmen

for (int count = 0; count < NUM_NAMES; count++)
{
cout << "Enter the name for salesman ";
cout << count + 1 << ": ";
cin >> names[count];

cout << "Now enter in the sales for each";
cout << " quarter for ";
cout << names[count] << endl;

// ask for quarter sales
for (int ndx = 0; ndx < NUM_SALES; ndx++)
{
cout << "Enter in data for quarter ";
cout << ndx + 1 << ": ";
cin >> sales[ndx];
}

cout << endl;

}

//display total sales for each salesman
double total = 0;

for (int ndx = 0; ndx < NUM_NAMES; ndx++)
{
cout << "Total for " << names[ndx] << " is $";
for (int ndx = 0; ndx < NUM_SALES; ndx++)
{
total += sales[ndx];
}
cout << fixed << setprecision(2) << total << endl;
}



return 0;
}
Last edited on
What issues are you having? What is your program not doing that it should be?

Please be more specific about what issues you are having. We can help you better if we know what you are having trouble with.
The program should display at the end the total sales for each salesmen.

So far the program only adds the last sales that were entered for the last salesmen, and adds that three times.

For ex: if the last three sale were 9, 10, 11, 12 it displays a total of 42, 84, and 126.
Topic archived. No new replies allowed.