Results 1 to 5 of 5

Thread: Why won't this code compile??

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    2

    Question Why won't this code compile??

    Every time I attempt to compile this code, I'm receiving a number of errors. Any ideas as to what the problem(s) might be?

    Thanks.




    public class MyMath
    {



    public static double exp(double x)
    {

    double dbloldGuess;
    double dblnewGuess = 1 + x;
    double dblcounter = 1;

    do
    {
    dblcounter++;
    dbloldGuess = dblnewGuess;
    dblnewGuess = dbloldGuess + ((x ** dblcounter) / counter);
    }
    while (Math.abs((newGuess - oldGuess) / newGuess) > 1e-15);

    return x;
    }
    }

  2. #2
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    What errors?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    just look at the variable names. You often forget the dbl prefix.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    New Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3
    Yup CornedBee is correct you forgot the
    dbl infront of several variable names:

    counter, newGuess, Oldguess

    and on the line

    ((x ** dblcounter) / counter);

    get rid of one of those *
    Mind over metal

  5. #5
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    if you are trying to multiply here:

    ((x ** dblcounter) / counter);

    you only should have 1 *.

    Also, avoid putting 'dbl' in front of all double variables because, as you can see, you are confusing yourself. If you need to remember what type of variable 'counter' is then keep it to one letter ( d for double, i for int, b for boolean, and so on... )
    To protect time is to protect everything...

Posting Permissions

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



Click Here to Expand Forum to Full Width