Need Help with this simple math problem

Write your question here.
I have a formula.

PV=FV/(1+r)^n


Fv = $250.00

the letter r is rates in percentages.
so 5 % is 0.05

n is the number of years. my number is 4

so on s calculator 250.00/(1+0.005)^4= 205.675618698

Here is what I have in c++ code



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  #include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;

int main(int argc, char *argv())
{
float pv, fv, r=0;
int n=0;

char answer = 0;
int mainloop = 1;
int firstloop = 1;


 while(firstloop> 0){
cout <<"Welcome. "<<endl;
cout <<"If you wish to use this program please enter Y for yes."<<endl;
cout <<"If you wish to exit type E for exit:";
cin>>answer;

if (answer == 'e'|| answer == 'E')
{
    cout<<"Good bye"<<endl;
     mainloop -- ;
     firstloop -- ;

    }
    else if (answer == 'y'|| answer == 'Y'){

     firstloop --;

    }
    else
    {
        cout<<"Your answer is not correct.. Try again."<<endl;

    }

 }


while(mainloop> 0)
  {

system("CLS");

cout<<"Enter the cost value FU:"<<endl;

cin>>fv;
cout<<endl;
cout<<"Enter the rates for example type in 50. That would represent 50%"<<endl;
cout<<":";
cin>>r;

cout<<"Enter the number of years:";
cin>>n;
r/100;


for(n;n>0;n-- ) {

 pv = pow(fv/(1+r),n);


cout<<pv <<endl;
}

system("pause");

  }




return 0;
}


It's not coming out right! what am I doing wrong here

The For loop is suppose to count down from 4,3,2,1 and as it does the ^n is suppose to change with that 
Last edited on
This pow(fv/(1+r),n); doesn't look the same as 250.00/(1+0.05)^4
instead, it is calculating (250.00/(1+0.05) ) ^4
I figure it out. Sorry I posted too soon. Here is my working program

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;

int main(int argc, char *argv())
{
float pv=0, fv=0, r=0, vp;
int n=0;

char answer = 0;
int mainloop = 1;
int firstloop = 1;


 while(firstloop> 0){
cout <<"Welcome. "<<endl;
cout <<"If you wish to use this program please enter Y for yes."<<endl;
cout <<"If you wish to exit type E for exit:";
cin>>answer;

if (answer == 'e'|| answer == 'E')
{
    cout<<"Good bye"<<endl;
     mainloop -- ;
     firstloop -- ;

    }
    else if (answer == 'y'|| answer == 'Y'){

     firstloop --;

    }
    else
    {
        cout<<"Your answer is not correct.. Try again."<<endl;

    }
 }


while(mainloop> 0)
  {

system("CLS");

cout<<"Enter the cost value FV:"<<endl;
cout<<":";
cin>>fv;
cout<<endl;
cout<<"Enter the rate value as a whole number. "<<endl;
cout<<":";
cin>>r;

cout<<"Enter the number of years:";
cin>>n;
r=r/100;


for(n;n>0;n-- ) {

 pv=pow((1.0+r),n);
 vp = (fv/pv);


cout<<vp <<endl;
}

system("pause");

  }

return 0;
}


If you enter 250.00 as your dollar value, and 5 as your rates, number of years being 4
205.675 will appear as one of the answers along with th
Topic archived. No new replies allowed.