Compile error, can someone have a look?
Posted: Sun Jan 29, 2006 9:25 pm
I am moving from Java to C++ and this code gives error, please tell me where is the error:
Code: Select all
#include<iostream>
using namespace std;
int rank[1000000];
void main()
{
long a, b, c;
while (cin>>a>>b)
{
//Calculate & Track for max
int max = 0;
for (int i = a; i <= b; i++)
{
if (rank[i] == 0)
rank[i] = findrank(i);
if (max < rank[i])
max = rank[i];
}
//Print out
cout << max;
}
}
int findrank(int& x)
{
int rank, next;
if (x == 1)
{
rank = 0;
}
else
{
if (x % 2 == 0)
next = x/2;
else
next = x*3+1;
if (next > 1000000 || rank[next] == 0)
rank = 1 + findrank[next];
else
rank = 1 + rank[next];
}
if (x < 1000001)
rank[x] = rank;
return rank;
}