Advertisement
Spocoman

High Jump

Sep 20th, 2023
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int jumpTarget, jump;
  7.     cin >> jumpTarget;
  8.  
  9.     int startJump = jumpTarget - 30;
  10.     int counter = 0;
  11.     int fall = 0;
  12.  
  13.     while (fall != 3 && startJump <= jumpTarget)
  14.     {
  15.         cin >> jump;
  16.  
  17.         if (jump > startJump) {
  18.             startJump += 5;
  19.             fall = 0;
  20.         }
  21.         else {
  22.             fall++;
  23.         }
  24.         counter++;
  25.     }
  26.  
  27.     if (startJump <= jumpTarget)
  28.     {
  29.         cout << "Tihomir failed at " << startJump << "cm after " << counter << " jumps.\n";
  30.     }
  31.     else
  32.     {
  33.         cout << "Tihomir succeeded, he jumped over " << jumpTarget << "cm after " << counter << " jumps.\n";
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement