I'm stuck and dont know how to turn FV = P ((r+1)^N-1)(r+1)/r into c++ code.
where, r = R/5200, the decimal equivalent of the weekly interest rate.

"Write a program that computes the future value of a "Holiday Club" account.

The idea is that every week, on Friday, a person deposits P dollars into a special savings account. The weekly deposit is always the same: P dollars. Before the first deposit is made, there is no money in the account. Whatever money is in the account earns interest at some particular fixed rate, compounded weekly. As the weeks go by, there is more and more money in the account, and so every week the amount of additional interest is larger and larger. Eventually the time arrives for purchasing holiday gifts. One Friday, instead of depositing another payment, the owner of the account withdraws all the money and spends it. "

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227`` `````` #include #include using namespace std ; /* PROTOTYPES */ void PrintDirections() ; /* Exactly what this function must do: Print directions for the user of the program. */ double GetPmt() ; /* Exactly what this function must do: Prompt the user to enter the amount of the weekly payment, read it in, and return it to the caller. */ double GetRate() ; /* Exactly what this function must do: Prompt the user to enter the amount of the annual interest rate, read it in, and return it to the caller. */ int GetNumWeeks() ; /* Exactly what this function must do: Prompt the user to enter the number of weekly payments, read it in, and return it to the caller. */ double Compute_FV(double P, double R, int N) ; /* Exactly what this function must do: Return the future value of N payments of P dollars at annual interest rate percentage R. */ void Report_FV(double P, double R, int N, double fv) ; /* Exactly what this function must do: Report to the user -- tell the user that fv is the future value of N payments of P dollars at annual interest rate percentage R. */ /* **************************************** */ /* MAIN */ /* **************************************** */ int main () { double pmt, rate ; int weeks; PrintDirections(); pmt = GetPmt() ; rate = GetRate() ; weeks = GetNumWeeks() ; } /* **************************************** */ /* PRINT DIRECTIONS */ /* **************************************** */ /* Exactly what this function must do: Print directions for the user of the program. */ void PrintDirections() { cout << endl ; cout << "This program will calculate the futrue calue of N\n" ; cout << "weekly payments of P dollars at annual interest\n" ; cout << "rate R." << endl ; cout << endl ; cout << "You will be prompted to enter P, R, and N (in that\n" ; cout << "order) and then the future value will be\n" ; cout << "calculated and written to the screen." << endl ; cout << endl ; } /* **************************************** */ /* GETPMT */ /* **************************************** */ /* Exactly what this function must do: Prompt the user to enter the amount of the weekly payment, read it in, and return it to the caller. */ double GetPmt() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); double pmt ; cout << endl ; cout << "You must now enter the amount of the payment P in\n" ; cout << "decimal form (for example: 54.55). Do *not*\n" ; cout << "include a dollar sign (\$). Do *not* include any\n" ; cout << "commas." << endl ; cout << endl ; cout << "Enter P, the amount of each weekly payment here ==> P = " ; cin >> pmt ; return pmt ; } /* **************************************** */ /* GETRATE */ /* **************************************** */ /* Exactly what this function must do: Prompt the user to enter the amount of the annual interest rate, read it in, and return it to the caller. */ double GetRate() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); double rate ; cout << endl ; cout << "Now you must enter the annual interest rate in\n" ; cout << "decimal form (for example: 8.125). Do *not*\n" ; cout << "include a percent sign (%). Do *not* include any\n" ; cout << "commas." < R = " ; cout << endl ; cin >> rate ; return rate ; } /* **************************************** */ /* GETNUMWEEKS */ /* **************************************** */ /* Exactly what this function must do: Prompt the user to enter the number of weekly payments, read it in, and return it to the caller. */ int GetNumWeeks() { int weeks ; cout << endl ; cout << "Now you must enter the number of weekly payments\n" ; cout << "as a whole positive integer (for example: 45). Do *not*\n" ; cout << "include a decimal point or any commas.\n" ; cout << endl ; cout << "Enter N, the number of weekly payments, here ==> N = " ; cout << endl ; cin >> weeks ; return weeks ; } /* **************************************** */ /* COMPUTE_FV */ /* **************************************** */ /* Exactly what this function must do: Return the future value of N payments of P dollars at annual interest rate percentage R. */ double Compute_FV(double P, double R, int N) { double r (r=R/5200) ; } /* **************************************** */ /* REPORT_FV */ /* **************************************** */ /* Exactly what this function must do: Report to the user -- tell the user that fv is the future value of N payments of P dollars at annual interest rate percentage R. */ void Report_FV(double P, double R, int N, double fv) { cout << endl ; cout << "Here is your answer\n" ; cout << endl ; cout << "The future value of "<
Last edited on
 I'm stuck and dont know how to turn FV = P ((r+1)^N-1)(r+1)/r into c++ code.
I can't tell if the -1 is part of the exponent, so:
FV = P * pow(r + 1, N - 1) * (r + 1) / r;
if it is, or
FV = P * (pow(r + 1, N) - 1) * (r + 1) / r;
if it isn't.
Thank helios that helped me !

Also im stuck on how to declare the future value (FV) and where to put it so that it outputs the write answer?

Can you help me on what is suppose to go here?
 ``123456789101112131415161718192021222324252627282930`` ``````/* **************************************** */ /* COMPUTE_FV */ /* **************************************** */ /* Exactly what this function must do: Return the future value of N payments of P dollars at annual interest rate percentage R. */ double Compute_FV(double P, double R, int N) { } /* **************************************** */ /* REPORT_FV */ /* **************************************** */ /* Exactly what this function must do: Report to the user -- tell the user that fv is the future value of N payments of P dollars at annual interest rate percentage R. */ void Report_FV(double P, double R, int N, double fv) { } ``````
Last edited on
 ``12`` ``````double FV = /*expression*/; return FV;``````
inside Compute_FV(). Or just return the expression.
Topic archived. No new replies allowed.