Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int targetSteps = 10000;
- //спира да върви: command == "Going home" или е постигнала целта си (извървени стъпки >= 10000)
- string command; //Going home или стъпки
- getline(cin, command);
- int walkedSteps = 0;
- while (command != "Going home") {
- //стъпки под формата не текст -> "1500" -> stoi("1500")
- walkedSteps += stoi(command);
- if (walkedSteps >= targetSteps) {
- cout << "Goal reached! Good job!" << endl;
- break;
- }
- getline(cin, command);
- }
- if (command == "Going home") {
- int stepsToHome;
- cin >> stepsToHome;
- walkedSteps += stepsToHome;
- if (walkedSteps >= targetSteps) {
- cout << "Goal reached! Good job!" << endl;
- }
- else {
- cout << targetSteps - walkedSteps << " more steps to reach goal." << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment