# Thread: Math formula (js -->C++)

1. ## Math formula (js -->C++)

I found this Python formula:
Code:
`(x + 300 * math.pow(2, float(x)/7) )`
same formula (javascript)
Code:
`Math.floor(x + 300 * Math.pow(2, x / 7))`
and i want to make it a C++ formula.. im a bigginer and i have no clue how to do powers and stuff.

Thanks,

Demon1s 2. Replace math.pow() with just pow() and it should work. 3. i get these errors:

Call to undifined function 'pow'
Illigal use of pointer

btw im using BCB 6 4. Of course you have to include the proper headers, which in this case would be math.h. 5. ahem

cmath

(just being a little terd) 6. oops double posted

2nd edit: actually math.h works 4 me 7. hmm... now i relized i missed like half the code ... i got that to work but heres the full JS code:
Code:
```points = 0;

outputnum = 0;

minlevel = 2;

maxlevel = 500;

for (lvl = 1; lvl <= maxlevel; outputnum = Math.floor(points / 4), lvl++) {

diff = Math.floor(lvl + 300 * Math.pow(2, lvl / 7));

points += diff;

if (lvl >= minlevel) {

document.writeln('Level ' + (lvl) + ' - ' + outputnum + ' xp');

}

}```
I want to have that, except as a function... so if i call it and input a level value it outputs the outputnum. heres my code:
Code:
```float func2(float lvl)
{

points = 0;

outputnum = 0;

diff = floor(lvl + 300 * pow(2, lvl / 7));
points += diff;
outputnum = floor(points/4),lvl++);
return(outputnum);

}```
It works except for it doesnt output the right numbers. could som1 please point out what im doing wrong?

btw if u wanna see python source of original thing and stuff heres the site i found forumula on: http://www.maddogcarter.com/runescape/xpformula.html 8. i don't see a loop?  9. Originally posted by Demon1s
oops double posted

2nd edit: actually math.h works 4 me
Yes it probably does. But the .h header files are non standard. One should use the non .h header files located in the std namespace whenever possible. 10. Originally posted by Jamsan
i don't see a loop?    umm this is wat i want to happen:

i have this field where u can type stuff... u press the button and lvl = the field and it does that formula and types the result into the other field... i jus wanna know how to make this formula work for c++ and not a for loop. 11. Originally posted by Demon1s
oops double posted

2nd edit: actually math.h works 4 me
They are both supposed to work( math.h and cmath ), but you should use cmath because it's the standard header file, and most compilers support math.h, in order to support old programs only. except i want it like a function u call (lvl = input field with button that sends the value to the function. It should return the answer too... i can do that on my own but i do not know how to use those math functions... i dont even know how to do that math) 13. a for loop exists in C++ as well....one of the 2 main loops used to control a program..... 14. i dun want a for loop.

I want to input a number that would do the formula for that number(eg: please enter a number: (input a number) and then it calculates the formula with lvl = number you input) 15. Originally posted by Demon1s
i dun want a for loop.
Then how do you plan to do the sum?  Popular pages Recent additions 