I am a beginner programmer and am trying out the Codility frog jump question. Here is my code solution:
int solution(int, int, int, unsigned long int&);
int main(){
unsigned long int stepsTaken = 1;
int x = 10;
int y = 85;
int d = 30;
solution(x, y, d, stepsTaken);
cout << "Total Steps Taken: " << stepsTaken << endl;
}
int solution( int X, int Y, int D, unsigned long int &stepsTaken) {
int currentPosition = X;
int positionToGetTo = Y;
int stepsJumpedEachTime = D;
currentPosition += stepsJumpedEachTime;
if(currentPosition < positionToGetTo){
stepsTaken++;
solution(currentPosition, positionToGetTo, stepsJumpedEachTime, stepsTaken);
}
return stepsTaken;
}
Now the problem I am having is when I attempt to fullfil the requirements to deal with a number range from 1-1000000000. If I change int y above to say 2000000 I get a negative returned. unsigned long int should return a positive number but when I use 2000000 it returns negative.