Sales and Profit Program

Hello I need help with my c++ program,
A well-regarded manufacturer of widgets has been losing 4% of its sales each year. The company’s annual profit is 10% of sales. This year, the company has had $10 million in sales and a profit of $1million. Determine the expected sales and profit for the next 10 years. Your program should produce and display in the following form:
The output is this,
SALES AND PROFIT PROJECTION
YEAR EXPECTED SALES PROJECTED PROFIT
1 $10000000.00 $1000000.00
2 $ 9600000.00 $ 960000.00
3 - -
- - -
10 - -
Totals: $ - $ -

This is my code:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
float sales = 0.04;
float profit = 0.10;
float exSales = 10000000.00;
float finalSales;
float proProfit;
int year;
float totalSales, totalProfit;

cout << "\tSALES AND PROFIT PROJECTION";
cout << "\nYEAR \t\tEXPECTED SALES \t\tPROJECTED PROFIT";

for (year=1; year<=10; year++)
{
finalSales = exSales * profit;
proProfit = exSales * sales;
cout << "\n" <<year <<"\t\t"<< setw(3)<< fixed << setprecision(2)<< finalSales <<"\t\t\t"<< setw(3) << fixed << setprecision(2) <<proProfit;
}

cout << "\n---------------------------------------------------------";
totalSales += finalSales;
totalProfit += proProfit;
cout << "\nTotal:" <<"\t"<< setw(3)<< fixed << setprecision(2)<< totalSales <<"\t"<< setw(3) << fixed << setprecision(2) <<totalProfit;



return 0;
}
I did an ugly code I know, but my teacher doesn't explain anything she just gave us notes and never explain anything

My output:
SALES AND PROFIT PROJECTION
YEAR EXPECTED SALES PROJECTED PROFIT
1 1000000.00 400000.00
2 1000000.00 400000.00
3 1000000.00 400000.00
4 1000000.00 400000.00
5 1000000.00 400000.00
6 1000000.00 400000.00
7 1000000.00 400000.00
8 1000000.00 400000.00
9 1000000.00 400000.00
10 1000000.00 400000.00
---------------------------------------------------------
Total: 409284524881555530032060431335424.00 400000.00

I need help please.
Last edited on
When posting code, please use code tags so that the code is readable


[code]
// code goes here
[/code]


You need to initialise variables when they are defined. totalSales and totalProfit aren't and have unknown initial values. Set them to 0. Also I think you need to keep the runing tally of ttalSales and totalProfit within the for loop. Perhaps:

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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	float sales = 0.04;
	float profit = 0.10;
	float exSales = 10000000.00;
	float totalSales = 0, totalProfit = 0;

	cout << "\tSALES AND PROFIT PROJECTION";
	cout << "\nYEAR \t\tEXPECTED SALES \t\tPROJECTED PROFIT";

	for (int year = 1; year <= 10; year++)
	{
		float finalSales = exSales * profit;
		float proProfit = exSales * sales;
		totalSales += finalSales;
		totalProfit += proProfit;
		cout << "\n" << year << "\t\t" << setw(3) << fixed << setprecision(2) << finalSales << "\t\t\t" << setw(3) << fixed << setprecision(2) << proProfit;
	}

	cout << "\n---------------------------------------------------------";
	cout << "\nTotal:" << "\t\t" << setw(3) << fixed << setprecision(2) << totalSales << "\t\t\t" << setw(3) << fixed << setprecision(2) << totalProfit;
}



        SALES AND PROFIT PROJECTION
YEAR            EXPECTED SALES          PROJECTED PROFIT
1               1000000.00                      400000.00
2               1000000.00                      400000.00
3               1000000.00                      400000.00
4               1000000.00                      400000.00
5               1000000.00                      400000.00
6               1000000.00                      400000.00
7               1000000.00                      400000.00
8               1000000.00                      400000.00
9               1000000.00                      400000.00
10              1000000.00                      400000.00
---------------------------------------------------------
Total:          10000000.00                     4000000.00

Oh okay my bad, but the projected profit should be 10% of the expected sales, and expected sales on year 2 should be 9600000.00 applying the deduction of 4% to the 10 million sales and so for the following year.
Sorry. My bad. I didn't read the description - just looked at the code!

Perhaps something like:

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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	const double sales = 0.04;
	const double profit = 0.10;

	double exSales = 10000000.00;
	double totalSales = 0, totalProfit = 0;

	cout << "\tSALES AND PROFIT PROJECTION";
	cout << "\nYEAR \t\tEXPECTED SALES \t\tPROJECTED PROFIT";

	for (int year = 1; year <= 10; ++year) {
		double proProfit = exSales * profit;

		totalSales += exSales;
		totalProfit += proProfit;

		cout << "\n" << year << "\t\t" << setw(3) << fixed << setprecision(2) << exSales << "\t\t\t" << setw(3) << fixed << setprecision(2) << proProfit;

		exSales -= exSales * sales;
	}

	cout << "\n---------------------------------------------------------";
	cout << "\nTotal:" << "\t\t" << setw(3) << fixed << setprecision(2) << totalSales << "\t\t\t" << setw(3) << fixed << setprecision(2) << totalProfit;
}



        SALES AND PROFIT PROJECTION
YEAR            EXPECTED SALES          PROJECTED PROFIT
1               10000000.00                     1000000.00
2               9600000.00                      960000.00
3               9216000.00                      921600.00
4               8847360.00                      884736.00
5               8493465.60                      849346.56
6               8153726.98                      815372.70
7               7827577.90                      782757.79
8               7514474.78                      751447.48
9               7213895.79                      721389.58
10              6925339.96                      692534.00
---------------------------------------------------------
Total:          83791841.00                     8379184.10

Last edited on
Thank you so much sir
Topic archived. No new replies allowed.