Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a formula in c++

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Does anyone know how to write an algebra formula in c++. The formula is K=H(i/(1-(1+i)^-t). I been trying for hours and no luck yet it.

Thanx
 
I'm assuming that H and K are floating point and i and t are integers.
Code:
double K, H;
int i, t;
// Somewhere you need to get i, k, and H.
// I'll assume that you've done that here
.
.
.
double Holdi = (double)i; // Put i to a float
// I'm breaking this out into parts starting with inner ()
i++; // (1+i)

// This loop creates i^t
for (int x = 0; x < t; x++)
   i*=i; // i=i*i;

double HoldExp = (double)1/i; // My math is fuzzy here. i^-t
double HoldMinus = 1-HoldExp; // 1 - (1+i)^-t)
Holdi /= HoldMinus; // i/(1-(1+i)^-t)

K = H / Holdi; // Solution

I'm the first to admit that my math is a bit fuzzy. I deal with data bases more than algebra. Also, I'm doing this from memory so what out for both math and coding errors but hopefully you get the idea.

Also, you can clean up this code and combine much of it. I seperated out so you can see how it should be done. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
all the variables must be doubles:
k=H(i/(1-pow(1+i,-t)). Do you must included the math library. <math.h>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top