I have to do this assignment but really don't understand the calling and called functions yet. Can someone help me in completing the assingment.
The assignment states:
Rewrite your program for computing the value of a sinking fund so that there is a C++ function that is called to calculate the value, i.e., a function that returns the accumulated value based on the number of years with the annual interest rate compounded monthly and a fixed-size monthly deposit.
My program is:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double R, r, t;
cout << " Enter a value for the year : " ;
cin >> t ;
cout << " Enter a value for the interest rate :";
cin >> r ;
cout << " Enter a value for the monthly deposit :";
cin >> R ;
double f, g, i, n, interest, S;
i = r / 12;
n = 12 * t;
f = 1 + i;
g = pow ( f, n);
S = R * ( ( g - 1 ) / ( i ) );
interest = r * 100;
cout << "\nThe value of your fund after " << t << " years will be "
<< "$" << S << " given monthly deposits of $" << R << " at " << interest << "%." << endl;
return 0;
}
#include <iostream>
#include <cmath>
usingnamespace std;
int name(double, double, double);
int main()
{
double R, r, t;
name(R,r,t);
cout << "\nThe value of your fund after " << t << " years will be "
<< "$" << S << " given monthly deposits of $" << R << " at " << interest << "%." << endl;
return 0;
}
int name(double R, double r, double t)
{
cout << " Enter a value for the year : " ;
cin >> t ;
cout << " Enter a value for the interest rate :";
cin >> r ;
cout << " Enter a value for the monthly deposit :";
cin >> R ;
double f, g, i, n, interest, S;
i = r / 12;
n = 12 * t;
f = 1 + i;
g = pow ( f, n);
S = R * ( ( g - 1 ) / ( i ) );
return (r * 100);
}
Its not fully correct but I'm just giving you a general idea of what a function is.