# 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. ## 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. 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.

3. thanks for the help, i'll see if that works. sorry for spamming the board i'm new at this.

Popular pages Recent additions