Running total

My problem has the user enter a name and sales total three times. I then have a table that displays the three names and their sales along with a gross total of the three sales at the end. The problem is that the gross total doesn't add up the sales, it just re-lists the three sales numbers the user entered. How do I fix this? Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  #include<iostream>
#include<iomanip>
#include<string>
using namespace std;

//structure that has variables for entering name and sales and accumulate total  
struct Sales
{
	string name;
	float sales;
	float gross;
	float total;
};

int main()
{
	int x;
	//running total initalized
	float total = 0;
	
	//object and array
	Sales s[3];

	//for loop has user enter info three times
	for(x = 0; x < 3; x++)
	{
		cout<<"Enter sales information # "<<x+1<<endl<<endl;

		//user enters name
		cout<<"Enter name: "<<endl<<endl;
		getline(cin, s[x].name);
		cout<<endl;

		cin.ignore();

		//user enters their sales total
		cout<<"Enter your sales total: "<<endl<<endl;
		cin>>s[x].sales;
		cout<<endl;

		//accumulates total
		s[x].total = total+s[x].sales;

		cin.ignore();

		system("cls");
	}

	//displays menu
	cout<<"SALES PERSON"<<setw(15)<<"SALES"<<endl;
	cout<<"_______________________________"<<endl;

	for(x = 0;  x < 3; x++)
	{
		cout<<s[x].name<<setw(15)<<s[x].sales<<endl;
	}

	cout<<"______________________________"<<endl;
	cout<<"TOTAL of SALES"<<endl;
	cout<<"______________________________"<<endl;

	
		for(x = 0;  x < 3; x++)
		{
			cout<<s[x].total<<endl;
		}

	cout<<endl;

	system("pause");
	return 0;
}
 
s[x].total = total+s[x].sales;


Here you're saying that each salesman's object of total = sales.
IE:
1
2
3
s[0].total = total + s[0].sales;
s[1].total = total + s[1].sales;
s[2].total = total + s[2].sales;


What you need to do is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>

using namespace std;

struct Sales {
	string name;
	float sales;
	float total;
} salesPerson[3], sale;

int main()
{
	cout << "Enter sales information # " << endl;

	for(int i=0;i<3;i++)
	{
		cout << "Enter name: ";
		cin >> salesPerson[i].name;

		cout << "Enter your sales total: ";
		cin >> salesPerson[i].sales;

		sale.total += salesPerson[i].sales;
	}

	cout << "\nSALESPERSON SALES" << endl;
	cout << "_________________" << endl;

	for(int i=0;i<3;i++)
	{
		cout << "Salesperson " << salesPerson[i].name << "'s sales: " << salesPerson[i].sales << endl;
	}

	cout << "_________________" << endl;
	cout << "TOTAL OF SALES" << endl;
	cout << "_________________" << endl;
	cout << sale.total;

	cin.get();
	cin.get();
	return 0;
}
Topic archived. No new replies allowed.