# My code is computing crazy numbers!

In the snippet below I put a breakpoint at the first line. The  local variables generated at start follow. Note that iGenerationMax is huge even though it is set to 99. I need help figuring out why it changed. Any help proffered will be much appreciated. :)

======== snippet=====================

int iGenerationMax = 99;
double fProbability = 0.500;

while (!Found && (i < iGenerationMax)){
double t = i;
//        if (k <= n && k > 0)
{  cur = PosteriorDensity(t, mu, k, n);
CumProb = CumProb + (prev + cur) / 2.0; }
if ((CumProb > fProbability) && !Found)
{   if (abs(PrevCumProb - fProbability) < abs(CumProb - fProbability)) {
iGeneration = i - 1;}
else {
iGeneration = i;
Found = true; } }
prev = cur;
PrevCumProb = CumProb;
Found = true;
i = i + 1; }
return iGeneration; }

=======Local Variables=============

VariableValue
prev0
cur0
CumProb0
PrevCumProb0
Foundfalse
i1
iGeneration1305670058
iGenerationMax1071124578
fProbability0

answered Jan 6 by (82,920 points)

Your variable i is probably not initialized so it contains some random value.

Please, share the entire code for verification, not just a snippet.

commented Jan 6 by (10,500 points)
As Peter suggested, sharing partial information is not going to help you.
If the break point was set @ "    int iGenerationMax = 99; "
I assume the function stack(& all other locals) are not yet initialized & are bound to have Garbage Values in them.You should check thier values after assignment.
commented Jan 8 by (190 points)
Hey guys, thank you for the suggestions. I did not post all my code because it seemed like too much of an ask.
commented Jan 9 by (82,920 points)
Sometimes it's better to post your entire code, even if it seems a lot (you can provide link to your project with the SHARE button, 3 buttons right of the RUN button), as some trickier questions may need all the information possible to solve.