1. #1

    Little help with my programming

    So I am taking a basics of C++ class and everything is going well...except for this one set of problems.

    If you all could take a look and tell me what I am doing wrong in the code (not setting the problem up right?) that would be fantastic.

    Problem 1:

    X2= a(b+c)^2

    My code to solve it:

    X2=a*(pow(b+c, a));

    On my calculator, I am getting 215.31 for this problem, yet my program seems to be coming up with 809.99. Any ideas as to why?

    Problem 2:

    X3= 5√abc (the fifth root of a*b*c)

    My code to solve it:

    X3=abc*1/5;

    For this particular one, I have not done this kind of math in 5 years, but I was going off an example our teacher provided us. I am coming up with 4.93

    Last one, Problem 3:

    X4= √(b^2-4ac)/2a

    My code:

    X4=sqrt((pow(b,2)-4*a*c)/2*a);

    I am getting 8.06 in my program, but 9.60 on my calculator

    I am not sure if I am just setting these up wrong, or I am just terrible at math lol, but in any case, a nudge in the right direction would be much appreciated. I do not want the answers to these, I just want to know if I am doing something fundamentally wrong in my code so I can fix it myself.

    Thank you!
    Gold selling site spam is an important part of our eco system.

    You see, there are currently to many puppies and kittens on this world.
    Every time a Goldseller spams his advertisement on the mmo-champion site, a puppy dies.
    Every time you ignore these threads and don't report them, a kitten dies.

  2. #2
    The Insane Kujako's Avatar
    10+ Year Old Account
    Join Date
    Oct 2009
    Location
    In the woods, doing what bears do.
    Posts
    17,987
    Problem 1: X2= a(b+c)^2

    Multiplication before division, and I dont know where you got using the power of 'a' from.

    Code:
    X2=(pow(a*(b+c), 2));


    Problem 2: X3= 5√abc (the fifth root of a*b*c)

    Look at the sqrt function. http://www.cplusplus.com/reference/cmath/sqrt/ It does not do what you are using it for. You can build an nth root method based on this... http://en.wikipedia.org/wiki/Nth_roo...rincipal_roots but I suspect you're looking for something simpler. Here is a thread on this specific issue (5th root). http://bytes.com/topic/c/answers/215...number-using-c

    Problem 3: X4= √(b^2-4ac)/2a

    Combine the first two processes.
    Last edited by Kujako; 2013-03-11 at 05:56 PM.
    It is by caffeine alone I set my mind in motion. It is by the beans of Java that thoughts acquire speed, the hands acquire shakes, the shakes become a warning.

    -Kujako-

  3. #3
    Nth root function sounds like it's beyond the scope of where his class is right now. Taking the 1/5 power of the value should suffice for a homework problem.

    Last problem is just a simple error regarding where parenthesis (or lack thereof) are.
    Last edited by Badpaladin; 2013-03-11 at 06:00 PM.

  4. #4
    Thank you very much Kujako.
    Gold selling site spam is an important part of our eco system.

    You see, there are currently to many puppies and kittens on this world.
    Every time a Goldseller spams his advertisement on the mmo-champion site, a puppy dies.
    Every time you ignore these threads and don't report them, a kitten dies.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •