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.
#include<iostream>
#include<iomanip>
#include<string>
usingnamespace 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;
}