Here is the task: The future value of a bank deposit is computed using the following:
Find the future value of a bank deposit
p principal, the amount deposited
r annual rate of interest
c number of times interest is compounded per year
n number of years
i interest rate per period
m total number of times interest is compounded
i = r / c
m = c * n
balance = p * ((1 + i))
Write a computer program using functions to:
a) Get p, r, c and n from the user
b) Calculate the value of i, m and balance
c) Display the results on the screen
d) Please make sure that you utilize the creation of your own class or class template in your code
Sample Output:
This program will calculate the future value of a bank deposit given the initial deposit, the annual interest rate, the number of times per year interest is compounded, and the number of years until maturity
Enter your initial deposit
100
Enter the annual interest rate
5
Enter the number of time interest is compounded per year
4
Enter the number of years before maturity
5
for an initial deposit of $100 at 5%
In 5 years you will have $128.204
Write your codes here:
#include<iostream>
using namespace std;
float interestfunc(float r, float c, float interest);
int compoundfunc(float c, int n, int compound);
float balancefunc(float p, float interest, float balance);
int main()
{
int n, compound;
float p, interest, c, r, balance;
cout << "Enter your initial deposit: ";
cin >> p;
cout << "Enter the annual interest rate: ";
cin >> r;
cout << "Enter the number of time interest is compounded per year: ";
cin >> c;
cout << "Enter the number of years before maturity: ";
cin >> n;
cout << "Your interest rate per period is: " << interest << endl;
cout << "The number of times interest is compounded: " << compound << endl;
cout << " Your balance is: " << balance << endl;
int compoundfunc()
{
float c;
int n, compound;
compound = c * n;
return compound;
}
float balancefunc()
{
float p, interest, balance;
balance = p * ((1 + interest)); <- //Here is where the error is supposedly located.
return balance;
}
When I wrote the code above I intended to use a function prototype but at first failed to carry the variables in each function. Now I receive an error that says "unresolved external link" something like that. I ran into an issue like this before but I never found a solution, anyone mind giving me their opinion?
Okay here now I see the problem:
#include<iostream>
using namespace std;
float interestfunc(float r, float c, float interest);
int compoundfunc(float c, int n, int compound);
float balancefunc(float p, float interest, float balance);
int main()
{
int n, compound;
float p, interest, c, r, balance;
cout << "Enter your initial deposit: ";
cin >> p;
cout << "Enter the annual interest rate: ";
cin >> r;
cout << "Enter the number of time interest is compounded per year: ";
cin >> c;
cout << "Enter the number of years before maturity: ";
cin >> n;
cout << "Your interest rate per period is: " << interestfunc(r, c, interest) << endl;
cout << "The number of times interest is compounded: " << compoundfunc(c, n, compound) << endl;
cout << " Your balance is: " << balancefunc(p, interest, balance) << endl;
But there seems to be another issue. When I debug the code an more than one debug error pops up saying that I am using the interest, compound, and balance without initializing them. When I click ignore on all of them the output works fine.
That is because you haven't initialized them and you are passing them as parameters to a function. You are passing them by value, which basically tells the compiler this is a read operation, you haven't initialized them so it is warning you of that. Either initialize them or change your functions such that you don't pass them in (because really it doesn't make sense to pass a parameter you are not going to use).
e.g.
1 2 3 4 5
float interestfunc(float r, float c)
{
float interest = r / c; //Notice: declaring local float variable interest, exists in this function only.
return interest;
}
Then you can change your call site to this: float interest = interestfunc(r, c); //Moved the declaration down to this line (in effect initializing as well...
Also, the names of your variables inside your function do not have to match the name of your interest variable outside the function scope, they are two entirely different variables.
The unresolved external whatever is an error that occurs in Visual C++6.0 Enterprise for me all the time. Just click rebuild instead of build, and it'll go around it. I do not know why.
Unresolved External means that the linker has gone looking for something and cannot find it. Generally, it means you have not linked to the right library, or you have not compiled some of your code, or you have compiled it but not linked to it. It is not a compiler error; the code compiled, it just relies on something that the linker cannot find. In MS land, this often translates to "didn't put it in your project" or "didn't add the right library path" or "didn't add the right library".
In this case, the linker went looking for a function that didn't exist, because you got the parameters wrong.