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

Pages: 12
Jan 29, 2015 at 8:58am
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 Jan 29, 2015 at 9:00am
Jan 29, 2015 at 9:44am
by e do you mean Euler number? If so, it is easy to get by using exp(1.0)
Jan 29, 2015 at 9:45am
How would I use it to say e^(rate * time) ? Ya thats what I meant.
Last edited on Jan 29, 2015 at 9:46am
Jan 29, 2015 at 9:47am
I'm trying to do dollars* e ^(rate * time) to find the new balance.
Jan 29, 2015 at 9:48am
std::pow(e, rate*time)
Jan 29, 2015 at 9:48am
I think I tried that too. Then what would I make e ?
Last edited on Jan 29, 2015 at 9:50am
Jan 29, 2015 at 10:04am
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 Jan 29, 2015 at 10:04am
Jan 29, 2015 at 10:09am
Yes, but I tried that and it's not working.
Jan 29, 2015 at 10:12am
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
Jan 29, 2015 at 10:18am
But instead of numbers I have rate and time though, how do I incorporate that?
Jan 29, 2015 at 10:21am
MiiNiPaa wrote:
std::pow(e, rate*time)


http://coliru.stacked-crooked.com/a/a4545c398a590b65
Jan 29, 2015 at 10:25am
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 Jan 29, 2015 at 10:29am
Jan 29, 2015 at 10:29am
if I want to choose what I want rate and time to be
You will assign anything you want to them anywhere you want.
Jan 29, 2015 at 10:32am
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 Jan 29, 2015 at 10:33am
Jan 29, 2015 at 10:36am
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
Jan 29, 2015 at 10:41am
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.
Jan 29, 2015 at 10:44am
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 
Jan 29, 2015 at 10:50am
I understand it partially.
Jan 29, 2015 at 10:53am
I noticed, you never actually read data, so this might be helpful: http://www.cplusplus.com/doc/tutorial/basic_io/
Jan 29, 2015 at 11:39am
> 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