Math formula (js -->C++)

This is a discussion on Math formula (js -->C++) within the C++ Programming forums, part of the General Programming Boards category; I found this Python formula: Code: (x + 300 * math.pow(2, float(x)/7) ) same formula (javascript) Code: Math.floor(x + 300 ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    29

    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.
    could som1 please help me?

    Thanks,

    Demon1s
    Last edited by Demon1s; 04-27-2003 at 05:59 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Replace math.pow() with just pow() and it should work.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    i get these errors:

    Call to undifined function 'pow'
    Illigal use of pointer

    btw im using BCB 6

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Of course you have to include the proper headers, which in this case would be math.h.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    ahem

    cmath

    (just being a little terd)

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    oops double posted

    2nd edit: actually math.h works 4 me
    Last edited by Demon1s; 04-27-2003 at 08:10 PM.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    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. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    i don't see a loop?

  9. #9
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    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. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    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. #11
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    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.
    none...

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    ok... well anyway... can any1 answer my newer question?
    the one about this formula:
    http://www.maddogcarter.com/runescape/xpformula.html

    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. #13
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    a for loop exists in C++ as well....one of the 2 main loops used to control a program.....

  14. #14
    Registered User
    Join Date
    Apr 2003
    Posts
    29
    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. #15
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Demon1s
    i dun want a for loop.
    Then how do you plan to do the sum?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  3. Help with C++ Math
    By aonic in forum C++ Programming
    Replies: 4
    Last Post: 01-29-2005, 03:40 AM
  4. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 02:14 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 09:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21