Feb 26, 2013 at 11:57pm UTC
Hello, I'm writing a program for my c++ class that requires me to read data from a file and the profits from each sales person. At the end i need to figure out the the total profits of all salespeople. However since i used a loop to process the data, I am a bit confused about how to calculate the total profits. I shall post my source code and the data file that goes along with it. Thanks to whoever decides to help.
using namespace std;
char PT1 = "\nAlhaji Kanu GTC SALES REPORT 02/26/13 ";
char CL1 = "Salesperson Name: ";
char CL2 = "Total Sales: ";
char CL3 = "Cost of Sales: ";
char CL4 = "Net Profit: ";
while(salesPerson != "stop")
inFile >> salesPerson;
inFile >> totalSales;
inFile >> salesCost;
void calculate (void)
netProfit = totalSales - salesCost;
cout << PT1 << endl;
cout << endl << endl;
cout << CL1 << "" << salesPerson << endl;
cout << CL2 << "" << totalSales << endl;
cout << CL3 << "" << salesCost << endl;
cout << CL4 << "" << netProfit << endl;
totalNet = netProfit;
cout << "\nThe total net profit is: $" << totalNet << endl;
(can't find an attach,ents button so here is the data)
Hickle 2245.78 1072.49
Persells 11710.14 9735.38
Tipay 4567.51 3119.22
Zuller 5793.59 4204.45
Feb 27, 2013 at 12:30am UTC
You're calling accumulate once in your main line. Also, accumulate isn't accumulating anything.
You want to initialize totalNet to zero. Then EACH time you canculate netProfit, you want to add it to totalNet. Then when you're done, you can print totalNet.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes it easier to read your code, makes it easier to respond to your question, and improves the chances of getting a response.