Each time you loop you overwrite the double finalpi with the statement
double finalpi = pistart + piloop;
pistart needs to be used only the first time. Either move it out of the loop or check if it...