code.cpp 801 B

1234567891011121314151617181920
  1. /* Create a function that takes an
  2. * array of hurdle heights and a jumper's jump height, and determine
  3. * whether or not the hurdler can clear all the hurdles.
  4. * A hurdler can clear a
  5. * hurdle if their jump height is greater than or equal to the hurdle height.
  6. */
  7. bool hurdleJump(std::vector<int> hurdles, int jumpHeight) {
  8. if (hurdles.size()==0){return true;}
  9. int greatestHurdleheight = hurdles[0];
  10. // loop through array of hurdles comparing the jump height to each hurdle
  11. // return true only if the jumper height is greater than EVERY hurdle in the array
  12. for(int i=0;i<hurdles.size()-1;i++){
  13. // compare each hurdle to the previous one, save greatest hurdle
  14. if(hurdles[i]<hurdles[i+1]){
  15. greatestHurdleheight = hurdles[i+1];
  16. }
  17. }
  18. return jumpHeight>=greatestHurdleheight;
  19. }