How do you use e to power of in this case?

Pages: 12
so I have this, I'm trying to use the formula B=Pe^(rt) , P is dollars deposited in an account for t years with the interest rate of r. How do I use e to the power of something?? I don't really understand how to use it. thx

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
#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std;

int main()
{
	//declare identifiers 
	float dollars;
    float rate;
	float time;
    float total; 

    //initialize identifiers
     total= (dollars*pow(exp(x), (rate*time))); 

	cout << fixed << showpoint << setprecision(2);

    //Enter values
	cout << "Enter the money you want to deposit now(P): " << dollars;
	cout << "Enter the interest rate: " << rate;
    cout << "Enter duration in year(t): " << time;
    cout << "   Your balance after 5 years is " << total; 

	cout << endl; 

	//terminate program
	system("pause");
	return 0;
}
Last edited on
by e do you mean Euler number? If so, it is easy to get by using exp(1.0)
How would I use it to say e^(rate * time) ? Ya thats what I meant.
Last edited on
I'm trying to do dollars* e ^(rate * time) to find the new balance.
std::pow(e, rate*time)
I think I tried that too. Then what would I make e ?
Last edited on
What is e exactly in your code?
MiiNiPaa wrote:
by e do you mean Euler number? If so, it is easy to get by using exp(1.0)
Last edited on
Yes, but I tried that and it's not working.
I tried that and it's not working.
Then you made a mistake.

What exactly is not working? How is it "not working"? What you thinnk should happen?

http://coliru.stacked-crooked.com/a/e32e31b7e4e4b969
But instead of numbers I have rate and time though, how do I incorporate that?
MiiNiPaa wrote:
std::pow(e, rate*time)


http://coliru.stacked-crooked.com/a/a4545c398a590b65
Ok I see sort of.. but if I want to choose what I want rate and time to be, would I put them equal to 0.0 or something?

Also I want total to equal that part like total = pow(exp(1.0), rate*time) too so what happens to total?
Sorry I'm a beginner, thanks.
Last edited on
if I want to choose what I want rate and time to be
You will assign anything you want to them anywhere you want.
So I did something like this and it failed.

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
#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std;

int main()
{
    //declare identifiers 
    double rate = 1; 
    double time = 2;
    float dollars;
    float total=0.0; 

    //initialize identifiers
    total= pow(exp(1.0), rate*time); 

     cout << fixed << showpoint << setprecision(2);
     
    //Enter values
      cout << "Enter the money you want to deposit now(P): " << dollars;
      cout << "Enter the interest rate: " << rate;
      cout << "Enter duration in year(t): " << time;
      cout << "   Your balance after 5 years is " << total; 

	cout << endl; 

	//terminate program
	system("pause");
	return 0;
}
Last edited on
It works exactly as written.
1
2
3
//total= pow(exp(1.0), rate*time); 
//total= pow(e, 2*1); 
total = 7.38906

You set total to 7.38906 on line 15 and did not change it after that. So it still equals 7.38906 on line 23 and output will be 7.38906
So for what I need to do is choose a number, in my case the rate has to be 0.5 and the time has to be 5 and I have to input that and it asks enter the amount. So that's where I'm stuck.
Maybe you want to calculate and write down result after you will know data you need?
1
2
3
4
int a, b, c;
c = a + b; //Gives you some random data
std::cin >> a >> b;
c = a + b; //Gives you sum of input a abd b 
I understand it partially.
I noticed, you never actually read data, so this might be helpful: http://www.cplusplus.com/doc/tutorial/basic_io/
> pow(exp(1.0), rate*time);
Shirley you can't be Sirius.

http://www.cplusplus.com/reference/cmath/exp/
Returns the base-e exponential function of x, which is e raised to the power x: ex.
Pages: 12