Need help with C++!!

Hey guys I am really needing some help with this program, I need to code a program that displays the following

Price Units Amount
9.00 1.00 9.00
8.00 2.00 16.00
7.00 3.00 21.00
6.00 4.00 24.00
5.00 5.00 25.00
Total: 35.00 15.00 95.00

Press any key to continue . . .

Here is the code that I am using:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	double prices[5] = { 9.00, 8.00, 7.00, 6.00, 5.00 };
	double amounts[5];
	double units[5] = { 1.00, 2.00, 3.00, 4.00, 5.00 };
	double total[3] = { 35.00, 15.00, 95.00 };
	int i;
	cout << fixed << "	Price	Units	Amount \n";
	for (i = 0; i < 5; i++)
	{
		amounts[i] = prices[i] * units[i];
		cout << fixed << setprecision(2)<< "	" << prices[i]<<"	"<< units[i]<< "	"<< amounts[i] << endl;
	}
	cout << fixed << setprecision(2) << "Total:	" << total[i] << endl;

		system("pause");
		return 0;		
}


And here is the output that I get:

Price Units Amount
9.00 1.00 9.00
8.00 2.00 16.00
7.00 3.00 21.00
6.00 4.00 24.00
5.00 5.00 25.00
Total: 2.00
Press any key to continue . . .

I dont know what the problem is :s but if anyone can help me out that would be great, I am already late with this assignment but I am able to turn it in by Thursday to get credit.

Thanks so much in advance!
Limit the scope of your variables for(int i=0; i<5; ++I)
then line 18 would not compile (if you do a desk test you'll realise that you are trying to access the array out of bounds)

I think that the total array should be calculated and no hardcoded. However, I don't see the meaning of total[0]'
Topic archived. No new replies allowed.