Interest Rate Calculator

I have a defective compound interest rate calculator: it gives out incorrect results. Now, I need to maintain the existing function types without adding anything new (e.g., arrays, switches). Can someone suggest a remedy?

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
31
32
33
34
35
36
37
38
39
40
41
42

#include <math.h>
#include <iostream>


using namespace std;

int main() {
	char exit;
	char again;
	double interestrate; //user-defined
	double initialprincipal; //user-defined
double finalamount;
double n = 12; //compounded monthly
int year = 1;
double base; //finalamount = initialprincipal * (1+(interestrate/n))^(50*12)
double exponent;
do {
	cout << "Interest Calculator (Compounded Monthly)" << endl;
	cout << "Please enter the initial amount invested in whole dollars." << endl;
	cin >> initialprincipal;
	cout << "Please enter the interest rate in whole numbers. (Under California law, the maximum limit is 12%.)" << endl;
	cin >> interestrate;
	
		base = (1 + ((interestrate*0.01) / n));
		exponent = (n * year);
		finalamount = (initialprincipal * (pow(base, exponent)));
		for (year = 1; year <= 50; year++) {
			
		cout << "After " << year << " years: " << finalamount << endl;
	}
//	cout << "You will have after 50 years: " << finalamount << endl;
	cout << "Would you like to make another calculation? (y/n)" << endl;
		cin >> again;
} while (again=='Y'||again=='y');



	cout << "Please press a key and <enter> to exit." << endl;
	cin >> exit;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.