here is my assisgnment and I can compile it and run it but the numbers dont seem to be correct....could someone take a look and see if my call function is wrong? thanks
Bryan
Assignment:
If a principal amout P, for which the interest is compunded Q times per year, is placed in a savings account, then the amount of money in the account (the balance) after N years is given by the following formula, where I is the annual interest rate as a floating-point number:
balance = P x (1 + I/Q)^NxQ
Write a C++ program that inputs the values for P, I, Q, and N and outputs the balance for each year up through year N. Use a value-returning function to compute the balance. Your program should prompt the user appropriately, label the output values, and have a good style.
Code:
#include <iostream>
#include <cmath>
void Balance(float, float, int, int, float&);
using namespace std;
int main()
{
float P,I,B;
int Q,i,N;
cout << "Enter the principal: ";
cin >> P;
cout << "Enter the annual interest rate: ";
cin >> I;
cout << "Enter the number of times money compounded per year: ";
cin >> Q;
cout << "Enter the number of years: ";
cin >> N;
for (i = 1; i <= N; i++)
{
Balance(P,I,Q,i,B);
cout << "The balance after " << i << " year(s), is: "
<< B << "." << endl;
}
return 0;
}
void Balance(float P, float I, int Q, int N, float& B)
{
B = (P * pow((1.0 + I/Q),N*Q));
}