### 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.
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 #include #include #include 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 # "<>s[x].sales; cout<
 s[x].total = total+s[x].sales;

Here you're saying that each salesman's object of total = sales.
IE:
 123 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:
 12345678910111213141516171819202122232425262728293031323334353637383940414243 #include #include 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.