printing pow

At line '25', I have the following error which I'm not sure how to resolve. The error is commented. I would appreciate it if someone could offer some guidance as to what I'm doing wrong. "cout<<"Balance after year "<<i+1<":\t"<<A[i]; /*error invalid operands of types 'const char [3]' and 'double' to binary 'operator<<'*/"

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
  #include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
	{
	/*	  Design a program to calculate the balance in a savings account at the Cache National Bank. 
		The program should accept a deposit and interest rate, 
		then calculate and print for each of the next 10 years the interest earned 
		and the balance at the end of the year.
		
		Compound Interest: A = P (1 + r/n)^(nt)*/
		
		double A[10], P[10], r, n=1, t=10;
		int i;
		
		cout<<"\nEnter the Principal amount you wish to deposit into Savings: ";
		cin>>P[0];
		cout<<"\nEnter the interest rate of the savings account: ";
		cin>>r;
		for(i=0;i<10;i++)
			{
				A[i]=pow((P[i]*(1+r/n)) (n*t));
				cout<<"Balance after year "<<i+1<":\t"<<A[i]; /*error invalid operands of types 'const char [3]' and 'double' to binary 'operator<<'*/
				P[i+1]=A[i];
			}
		return 0;
	}
One of your << is just a <.
Whitespace is your friend, learn to use it.

Adding whitespace to line 25 makes the reason for the error easier to spot:
cout << "Balance after year " << i + 1 < ":\t" << A[i];
As dutch points out one of the insertion operators (<<) is a single <.

Your compiler doesn't care about whitespace, it is useful when humans read the code.
> A[i]=pow((P[i]*(1+r/n)) (n*t));
Pow takes two parameters, you forgot a comma.
http://www.cplusplus.com/reference/cmath/pow/

> P[i+1]=A[i];
That +1 is a trap.
> double A[10], P[10],
On the last iteration of the loop, when i==9, that +1 makes an array overrun on your P array.
Topic archived. No new replies allowed.