Advertisement
Spocoman

04. Walking

Sep 10th, 2023
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int neededSteps = 10000;
  8.  
  9.     string input;
  10.  
  11.     while (neededSteps > 0) {
  12.         getline(cin, input);
  13.         if (input == "Going home") {
  14.             getline(cin, input);
  15.             neededSteps -= stoi(input);
  16.             break;
  17.         }
  18.         neededSteps -= stoi(input);
  19.     }
  20.  
  21.     if (neededSteps <= 0) {
  22.         cout << "Goal reached! Good job!\n";
  23.     }
  24.     else {
  25.         cout << neededSteps << " more steps to reach goal.\n";
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement