i can't fix it! its driving me nuts

This is a discussion on i can't fix it! its driving me nuts within the C Programming forums, part of the General Programming Boards category; This is supposed to compute iMax^3 + iMax-1^3 + iMax-2^3...1^3 Instead, it doesn't . How can i add up the ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    21

    i can't fix it! its driving me nuts

    This is supposed to compute iMax^3 + iMax-1^3 + iMax-2^3...1^3
    Instead, it doesn't . How can i add up the terms in my for loop? It is setup so it only adds iMax^3 and iMax-1^3, but i don't know how to fix it.

    #include <stdio.h>
    #include <math.h>
    void cube(void);
    int main(void)
    {
    cube();
    return 0;
    }

    void cube(void)
    { int iMax, iAns, iCube, iNumber;
    printf("input max integer: ");
    scanf("%i", &iMax);
    iAns = pow(iMax,3);
    for (iNumber=1; iNumber <iMax; iNumber++)
    iCube = pow(iNumber,3) + pow(iMax,3);
    printf("Cube is : %i", iCube);
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Stop spamming the board. Use your existing thread.
    2) Use code tags. See left if you don't know how.
    3) Why are you using the power function?
    Code:
    int cubethis( int tc )
    {
        return tc * tc * tc;
    }
    
    int foo( int f )
    {
        int x,y=0;
        for( x = f; x > 0; x-- )
            y += cubethis( x );
        return y;
    }
    Try something like that. That should give you:

    x = foo( 5 );
    x = 5^3 + 4^3 + 2^3 + 1^3;

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    21
    thanks for the help, i'll see if that works. sorry for spamming the board i'm new at this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. This is driving me nuts.
    By Matt13 in forum C Programming
    Replies: 3
    Last Post: 03-25-2004, 09:55 AM
  4. This compiler is driving me nuts
    By martin_00 in forum C Programming
    Replies: 32
    Last Post: 12-31-2002, 02:25 PM
  5. driving me nuts
    By boontune in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2002, 04:35 AM

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