Is my code right?

Write a program that computes the amount of money in a bank account using the
compounded interest formula.
A = P(1 + r/100*k)^k*n
You should ask the user to enter the following:
Initial deposit double P
Annual rate double r ( you should enter 8.5 for 8.5%)
Number of compounds per year int k (which is usually 1, or 12, or 365, or 366 if leap year)
# of years int n
The code should use a loop to compute the amount double A over the time period i = 1 . . n years.

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

int main() {

	double P, A, r;
	int i,k,n;
	cout << "Enter the intital deposit.";
	cin >> P;
	cout << "Enter the annual rate.";
	cin >> r;
	cout << "Enter the number of years.";
	cin >> n;
	cout << "Enter the number of compounds per year.";
	cin >> k;
	for ( i = 1; i <= n; i++)
	A = P * pow( 1 + r / 100 * k, k*i);
	cout << A << " over the time period of " << n << " years"<<endl;
	return 0;
	}
Yes, mostly it looks all right (I suppose you test it to see if it works all right). In future I hope you will read some article on coding style, however for now it looks ok :)
Topic archived. No new replies allowed.