-2

I'm working on a program where the monkey climbs a tree.

10 feet takes 10 minutes. he falls back 3 and rests for 10 minutes.

the code I have written I thought worked when I traced it on paper, but returns stack overflow when I run the program.

*edit - ok so somehow i no longer get a stack overflow, but i don't get the result i need. it prints 30 regardless of the poleHeight. Ive tried tracing it but i don't see where Im making a mistake.

for poleHeight= 18;

static double climbTime(double poleHeight){

    double time = 0.0;
    double t = 10.0;
    double climbed = 7.0;

    //base case
    if(poleHeight <= 10.0){
        time = poleHeight;  
    }
    else{
        poleHeight = poleHeight - climbed;
        t = t + 10.0;
        climbTime(poleHeight);
    }

    return (time + t + 10.0);

}
cee
  • 9
  • 2
  • 7

1 Answers1

0

if you have stack overflow - that means either your base case is never true or you stack size is too small for the task(which is less likely)

A_P
  • 331
  • 3
  • 15
  • the base case should become true. i am subtracting the number so eventually it should become 10 shouldnt it? – cee Oct 14 '15 at 01:40