Equation result problem

Hey guys so I am messing around with log base e and I have been getting a different calculator answer compared to the compiler.

1
2
3
4
5
6
7
8
9
10
11
double rm1,rm2, t1,t2, om1,om2;
rm1=om1*exp(-0.00012*t1);
om1=100;
t1=1000;
rm2=om2*exp(-0.00012*t2);
om2=250;
t2=275;
output<<"\nThe amount of remaining material after 1000 years is: "<<rm1<<endl;
cout<<"\nThe amount of remaining material after 1000 years is:" <<rm1<<endl;
output<<"\nThe amount of remaining material after 275 years is: "<<rm2<<endl;
cout<<"\nThe amount of remaining material after 275 years is:" <<rm2<<endl;


I'm only giving partial code because the other stuff is correct and is part of a different problem. Basically, the compiler is giving me 1.69813e-313 while my calculator is giving me 88.69204367. The second part of the equation gives a different compiler answer to my calculator as well.

The equation is: remaining material = (original material)*e^-0.00012t1


Anyone know why my calculator and compiler answer are different?
Last edited on
Yes, All the numbers that you're putting directly into om1, t1, om2, and t2 need to have .0 after them, otherwise they're treated... differently.

-Albatross
Last edited on
Hmmm... Didn't seem to do anything when I added .0.

And I should have done that earlier because the variables are "double"


Question #11

The amount of remaining material after 1000 years is: 1.69779e-313

The amount of remaining material after 275 years is: 1.50529e-307
Last edited on
Ah... I'm an idiot. Of course. You're setting the values for your om1, t1, om2, and t2 after you're using them. When you use them in your equation, they contain garbage, not the values you wanted to be used. I think you can figure out how to fix the problem.

I need coffee. And I need to sleep more.

-Albatross
Last edited on
Thank You Albatross. Looks like it worked, I'm getting the same calculator answers.

Learned my lesson :)
I also have one more question... I am writing another formula which requires the use of λ.

How exactly can I use this in C++?
If you're referring to the distribution, I think you'll need an external library for that. Otherwise, what are you referring to?

-Albatross
Topic archived. No new replies allowed.