1. ## One small problem!

Need to take in two variable ranges, 3 to 6 and 1 to 4. The program is supposed to calculate the cubed value of the ranges (432 & 100). I have written the functions and they work fine but I can't accumulate the totals! At the moment it is returninf the cubed values for the last digit of each range (54 & 36). Probably something really easy but I'm stuck! Here is the code:

#include<stdio.h>
#include<conio.h>

main()
{

int firsta,
lasta, /* first range */
firstb,
lastb, /*second range */
rangea,
rangeb;

int sum_of_cubes (int, int);

printf("Enter first range : ");
scanf("%d%d", &firsta, &lasta);
printf("Enter second range: ");
scanf("%d%d", &firstb, &lastb);

rangea = sum_of_cubes (firsta, lasta);
rangeb = sum_of_cubes (firstb, lastb);

printf("first range cubed %d\nsecond range cubed %d", rangea, rangeb);

getch();
}
int sum_of_cubes (int first, int last)
{
int number = first,
sum = 0,
parameter,
total;

int cube (int);

while (number <= last)
{
/* this is the bit I'm stuck on!!
parameter = cube(number);
sum = parameter;
number += 1;
*/
}

return sum;
}

cube (int item)
{
return item *3 *3;
}

2. ## Re: one small problem below.

Sorry, the JFC post below was meant to be me, if anyone is kind enough to reply can they do it through this one please? Thanks.

3. > return item *3 *3;
Cube is
item * item * item

4. ## re above:

Thanks Salem, I've been spending so long on this that I put a 3 instead times the item to the power of 3! Doh.

The program is still not giving me a combined total however, it's merely reporting the cube of the last digits in each range. Any ideas how to store them as a running total?

5. ## Cancel the above!

Cracked it.

6. Code:
```int sum_of_cubes(int first, int last) {
int number = first,
sum = 0;
while(number <= last) {
sum += cube( number );
number ++;
}
return sum;
}```