I'm working on the project Euler series in my free time for fun, and right now, I'm on problem #14. The specs of the project can be found here: http://projecteuler.net/index.php?se...problems&id=14.

I'm doing this in C++, and here is my sourcecode:
Code:
#include <iostream>
#include <windows.h>
using namespace std;

void main()
{	unsigned long int answer=1,length=0,test,temp,cycle=0;
	for(test=1;test<1000000;test++)
	{	temp=test;
		while(temp>1)
		{
			if(temp%2==0)
			{	temp=temp/2;
				++cycle;}
	
			else{
				temp=(3*temp)+1;
				++cycle;}	
		}

		if(cycle>length)
		{length=cycle;
		answer=test;}
	
	}
	cout<<"number: "<<answer<<" length: "<<length+1<<"\n"; //add 1 to include '1' in the sequence, since it was excluded from the while loop
	system("pause");
	}
However, this incorrectly returns the answer of 999999 and a length of 131435088. I review my code several times, and don't see what is the problem.