Im trying to solve the Collatz problem. It's all working except of one my int highest which should compare whether counter of one number is greater than counter of next number seems not to be working. I also tried my highest variable as array but still getting no result. Thanks for your any advice.
#include <vector>
#include <iostream>
using namespace std;
int main()
{
__int64 num;
int i;
int counter=0;
//vector<int> a(1000000);
//vector<int> b(1000000);
__int64 highest=0;
int j=0;
for(j=2;j<=1000000;j++)
{
num=j;
counter=0;
for(i=0;i<1000000;i++)
{
cout<<"num is: "<<j<<endl;
if(num==1)
{
break;
}
if(num%2==0)
{
num = num/2;
counter++;
cout<<num<<endl;
}
else if(num%2!=0)
{
counter++;
num= (num*3)+1;
cout<<num<<endl;
}
}
cout<<"counter: "<<counter<<endl;
//this part is not working
if(highest<=counter)
{
highest=counter;
cout<<"highest is: "<<highest<<endl;
}
}
return 0;
}