I'm trying to solve project Euler questions and on the 14th question when i compile it the exe keeps on crashing. Here is my code
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int counter_array[1000000];
int array_key=0;
for(int x=1;x<=1000000;x++)
{
int y=x;
int z=1;
int counter=0;
while(z==1)
{
if((y%2)==0 && y>1)
{
y=y/2;
}
else
{
if((y%2)!=0 && y>1)
{
y=(3*y)+1;
}
else
{
z=2;
}
}
counter++;
counter_array[array_key]={counter};
array_key++;
}
}
int temp=0;
int pos=0;
for(int i=0; i<1000000;i++)
{
if(counter_array[i]>temp)
{
temp=counter_array[i];
pos=i;
}
}
cout << pos << "----->"<<temp << endl;
}
I don't know what went wrong. Please forgive me for my mistakes I'm really new at this .