rate calculator function.

I have to make a function that will calculate the interest using this formula current * (rate + 1)^ time.. however i cant get it to calculate correctly anybody have an idea of how to get this done?
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
  #include <iostream>
#include <cmath>

using namespace std;

float future_value(float current, float interest, float years)

     {
         return (current * (interest + 1) * years);

    }


int main()
{
    float now, interest, years;
    cout << "== How Much Money Will You Have? ==" << endl;
    cout << "How much money do you have now?" << endl;
    cin >> now;
    cout << "What's the interest rate? (format: 0.05 for 5%)" << endl;
    cin >> interest;
    cout << "How many years will the money sit? (fractions are OK)" << endl;
    cin >> years;
    cout << "You will have " << future_value(now, interest, years) << " in " << years << " years." << endl;
}
I figured it out

#include <iostream>
#include <cmath>

using namespace std;

float future_value(float current, float interest, float years)

{
return (current * pow((1 + interest), years));

}


int main()
{
float now, interest, years;
cout << "== How Much Money Will You Have? ==" << endl;
cout << "How much money do you have now?" << endl;
cin >> now;
cout << "What's the interest rate? (format: 0.05 for 5%)" << endl;
cin >> interest;
cout << "How many years will the money sit? (fractions are OK)" << endl;
cin >> years;
cout << "You will have " << future_value(now, interest, years) << " in " << years << " years." << endl;
}

Topic archived. No new replies allowed.