future value

I seem to be having trouble with my program. It was easy until my teacher decided to make it where you had to have the function outside the base program than return it. The problem i am facing is that no errors that are popping up, but it is calculating at the end just putting the original value and not the future value. I'm about to lose my mind trying to figure this out so any help would really be appreciated.
also it is the FUTURE VALUE C++ question 402:12 on the c++ early objects ninth edition book if that helps any.

#include <iostream>
#include <cmath>
#include <math.h>
#include <iomanip>

using namespace std;

double futureValue(double, double, int);

int main()
{
double p = 0; // preasent value
double i = 0; // Interest rate
int t = 0; // Number of months
double accountValue = 0;

// Current Value
cout << " Enter present amount: $";
cin >> p;

// Enter Interest Rate
cout << " Enter an interest rate: ";
cin >> i;

// Enter Time Periods
cout << " Enter number of months it will be in your account: ";
cin >> t;

accountValue = futureValue(p, i, t);
//DISPLAY RESULTS
cout << fixed << showpoint << setprecision(2);
cout << " Your future value without adding to original is: $" << accountValue << endl;
return 0;
}

// Function for future value
double futureValue (double p, double i, int t)
{

double accountValue;
accountValue = p * pow(1 + i / t, -1 / t);
return accountValue;
}

and before some says it. yes i have seen this on here before, but not while having to take the function out than return it and that's whats got me messed up.
Dividing an integer with an integer will give you an integer in C++. If you instead want a floating point value, with the decimal part intact, you need to make sure at least one of the operands is a floating point value.

 
accountValue = p * pow(1 + i / t, -1.0 / t);
i actually just figured it out. changed two things

This fixed it: double futureValue(double, double, double); / double futureValue (double p, double i, double t)



this calculated it like i wanted: accountValue = (p * pow(1 + i / t, -1 / t) ) + p;

thank you for the help.

Topic archived. No new replies allowed.