Problem with chessboard question's total result

question asks to calculate the total number of grains at square 64 of chessboard. when doubling from previous one, eg- 1 at sq1, 2 at sq2, 4 at sq 3, 8 at sq 4, so how much at sq 64.
code``` uint64_t total(void){
uint64_t totals;
for(uint64_t i=1; i<=64; i++){
if(i==1){
totals = 1;
}else{
totals = (totals*2);
}

}
printf("total of %lu\n ", totals);
return totals;

}```

test error says Test Failure Expected 18446744073709551615 Was 9223372036854775808 Your Output total of 9223372036854775808 ./

here i believe, test result is wrong?? or i am wrong??

The function total gives the sum of all the squares. Note that it does not take any argument, because this sum is independent of any given square.

There is a different function that returns the number of grains in a given square.

look, there are two functions, 1) uint64_t square(uint8_t index);
2) uint64_t total(void);

have passed all the test for square(). the 2nd function calculate the sum of default 64sq(the total squares in chess).

and for that, written function is:-

uint64_t total(void){
uint64_t totals;
for(uint64_t i=1; i<=64; i++){
if(i==1){
totals = 1;
}else{
totals = (totals*2);
}

in test result- Test Failure Expected 18446744073709551615 Was 9223372036854775808
Your Output total of 9223372036854775808 ./

so, what i am getting is, there expected 18446744073709551615 is at 63rd.
and 9223372036854775808 is at 64th, accordiing to my function.

Consider the total after just 2 squares. The result should be 1 + 2 = 3. Does your function produce the total of 3 if the loop ends at i<=2?

sorry, was my bad, didn’t got the question right.

i got you and it works now!

uint64_t total(void){
uint64_t totals=0;
uint64_t doubles;
for(uint64_t i=1; i<=64; i++){
if(i==1){
doubles = 1;
totals += doubles;
}else{
doubles = (doubles*2);
totals += doubles;
}

}
printf("total of %llu\n ", totals);
return totals;

}

output: 18446744073709551615.

You might want to get familiar with using codeblocks. Unformatted code is hard to read.