Program formula needs fixing

I need this program to do http://pastebin.com/2Kuf9ekD . The program runs fine, however, when I input the given numbers I get the wrong answer.
For some weird reason my pow isn't highlighted blue, maybe that has to do with it?










#include <math.h>
#include "stdio.h"
#include <iostream>
using namespace std;

int main (void){

//declare variables ---
double investedAmount;
double interest;
double numberofYears;
double conversion;
double maturity;
double m;
double y;
//---------------


cout << "please enter amount saved = " ;
cin >> investedAmount ;

cout << "amount of interest = " ;
cin >> interest;


cout << "number of years: ";
cin >> numberofYears;

cout << "number of conversions per year ";
cin >> conversion;

interest = interest / 100; // divides interest by 100

// Formula for calculating maturity value


m = (1+(interest/conversion));

y = (numberofYears);

maturity = investedAmount*(m*pow(y,m)); ///maturity = investedAmount* (1+(interest/conversion))*pow(numberofYears,conversion)

//--------------------


cout << "Maturity Value " << maturity << endl;
system ("pause"); // break

return 0; // return nothing

}
Last edited on
> however, when I input the given numbers I get the wrong answer.
It would be wonderful if you could provide a test case.
You did not follow the formula in the link. You compute
S = D (1+P/M) Y^(1+P/M)

> For some weird reason my pow isn't highlighted blue, maybe that has to do with it?
No.


¿why are you dividing `interest' by 10000?
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
43
44
45
46
47
48
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    double investedAmount;
    double interest;
    double numberofYears;
    double conversion;

    cout << "please enter amount saved = " ;
    cin >> investedAmount ;

    cout << "amount of interest = " ;
    cin >> interest;

    cout << "number of years: ";
    cin >> numberofYears;

    cout << "number of conversions per year ";
    cin >> conversion;

    // Formula for calculating maturity value
    //
    //  S = D ( 1 + P/M)^YM   
    //
    //  where:
    //     D = Investment Amount
    //     P = Interest
    //     Y = Number of Years
    //     M = Conversions/Year

    double D = investedAmount;
    double P = interest/100.0;
    double Y = numberofYears;
    double M = conversion;

    double S = D * pow ( ( 1 + P/M), Y*M);

    double maturity = S;

    cout << "Maturity Value " << fixed << setprecision(2) << maturity << endl;

    return 0;
}
I fixed the interest, the problem is I don't know how to fix the formula.
Chervil I used what you gave me and only got 5005.91
Last edited on
5000*(1 + 5.25/(100*4))^(2.25*4)
= 5622.60

In order to get 5005.91 I guess you used
5000*(1 + 5.25/(10000*4))^(2.25*4)

That is, an interest rate of 0.0525% p.a.
Last edited on
I'm sorry I'm using the coded formula you gave me, double S = D * pow (( 1 + P/M), Y*M); . I'm just not getting 5622.6
The code I posted in its entirety works correctly. If you just used part of my code, together with some of your existing code, then you may be dividing the interest by 100 in more than one place.
Last edited on
You're right! Thank You! :D
Topic archived. No new replies allowed.