### 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.
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?
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include #include 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.