### Really weird Infinite Loop problem

I'm having a really weird infinite loop problem here. My whole program is 27k lines so I won't post the whole thing but here's what's in the main:

 ``12345678910111213141516`` ``````cout << "Running 60 min average" << endl; create60minaverage(); for (lastone = 0; lastone <= 8; lastone++) { createlast1minaverage(); createlast5minaverage(); createlast10minaverage(); createlast15minaverage(); createlast1houraverage(); }``````

and here's part of one of the functions:

 ``123456789101112131415161718192021222324`` ``````int createlast1minaverage() { a = 38 + lastone; x = 33; if (lastone > 0) cout << "Last 1 min average" << lastone << endl; if (lastone == 0) cout << "Last 1 min average" << endl; for (y = lastone + 1; y < 121614; y++) { y2 = y - ( 1 + lastone); datetime[a][y] = datetime[x][y2]; zcot = ((y/121614.2f) * 100.2f); cout << "\r" << zcot << "% "; } return 0; }``````

Now, I've run this before, and it ran just fine. Added some other functions that come AFTER this, and then it stopped working properly.

The functions within the main for loop are basically the same. None modify "lastone" or y other than the for loops.

Now, when I run this, when lastone = 8, the "last1houraverage()"; turns into an infinite loop. Never goes above about 2 percent. So I changed the for loop in the main to do just up to 7 instead of 8. And when I did that, the 1hour function for lastone = 7, became an infinite loop. So I added a break after the 15min average and before the 1hr average so that when lastone >= 6 it just breaks. When I did that, the 15min average function became infinite!

I started adding breaks into the functions when lastone met a certain point, and it'd ignore the breaks and continue its infinite run!

So I commented out the entire for loop and the functions in the main() and now the create60minaverage() has become an infinite loop!

I am at my wit's end. I can't see how these things could be doing this! Its almost like a cruel joke but short of it being a bug with MSVS 2012, I don't know what to do.

Any help or insight would be greatly appreciated.

Just to clarify, among these 6 functions in the main(), whichever runs LAST, it turns into an infinite loop and I don't receive any error message or anything.
Apart from the bad style of programming of using global variables I do not see the reason of the infinite loop in the code you presented. In general you should not ask such questions in the forum. All what you need is to insert some output of critical vatiables that to see what is wrong.
I can't speak to the "style", as its the only method I really know. I don't see the reason for the infinite loop either and it does have outputs for the variables.

How would you have written that part whereby there would not have been a use of global variables? This is only a small part of my program and the only part where I'm using a for loop in the main(). But, as I mentioned, even when I eliminate the for loop, the former function becomes defunct.

Is there someway that the global variables that I'm using could somehow be affected in ways that we're not seeing in this code?
Topic archived. No new replies allowed.