I am also kind of a beginner, but your code is not easy to follow. You have foreign data types to me with pointer addition, etc., but here is my two cents.
greatestFactor is not initialized, but not sure if that is relevant. listPtr is of type uint64_t, while factorCount is of type int, and currentDivisor is a third type, unsigned int. In your pointer addition piece,
*(listPtr + factorCount) = currentDivisor; |
you have them all trying to work together, but that shouldn't simply affect the value OF currentDivisor (which is the only outuput). Should it?
You are also using the sqrt function, but that should be found in a math header, not in iostream or cstdint, but I'm sure that would just give you a syntax error, so you probably just left that out by mistake here.
OK so I just ran it myself to see the actual output, and it wouldn't compile without first including cmath and then doing what kbw has to convert the type inside the sqrt function to long double. However, since that type is not the same, something erroneous may be happening, but AGAIN this has nothing to do with the value of currentDivisor...
Your problem SEEMS systematic in that the numbers are doubling, so it may be something simple we are missing. And of course, 128 would obviously be wrong as a factor because since the original number is odd, 8 will never go into it.
If it were me, for simplicity, I would probably get rid of the pointer stuff and make them all the same data type (a more simple type) for testing, then edge my way into the more advanced stuff from there, probably starting with the additional data types first. Hope I have been helpful.