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

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 04-27-2003
Demon1s
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
• 04-27-2003
Magos
Replace math.pow() with just pow() and it should work.
• 04-27-2003
Demon1s
i get these errors:

Call to undifined function 'pow'
Illigal use of pointer

btw im using BCB 6
• 04-27-2003
Magos
Of course you have to include the proper headers, which in this case would be math.h.
• 04-27-2003
golfinguy4
ahem

cmath

(just being a little terd)
• 04-27-2003
Demon1s
oops double posted

2nd edit: actually math.h works 4 me
• 04-27-2003
Demon1s
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
• 04-27-2003
Jamsan
i don't see a loop? :confused:
• 04-27-2003
golfinguy4
Quote:

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.
• 04-27-2003
Demon1s
Quote:

Originally posted by Jamsan
i don't see a loop? :confused:
:confused: :confused: :confused:

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.
• 04-28-2003
ammar
Quote:

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.
• 04-28-2003
Demon1s

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)
• 04-28-2003
Jamsan
a for loop exists in C++ as well....one of the 2 main loops used to control a program.....
• 04-28-2003
Demon1s
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)
• 04-29-2003
Magos
Quote:

Originally posted by Demon1s
i dun want a for loop.
Then how do you plan to do the sum? :rolleyes:
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last