From bdf1b02fc43c26875052a76e000efed03605c748 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sat, 20 Jul 2024 15:26:07 +0300 Subject: [PATCH] Fix Lesson 2 Task 4 --- Lesson_2/Task_4/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lesson_2/Task_4/main.cpp b/Lesson_2/Task_4/main.cpp index 7c4d380..8e1dd59 100644 --- a/Lesson_2/Task_4/main.cpp +++ b/Lesson_2/Task_4/main.cpp @@ -7,17 +7,20 @@ int main() char str[256]; cout << "Enter some string: "; cin.getline(str, 256); - int words = 1; + int words = 0; bool space = false; for (int character = 0; str[character] != 0; ++character) { if (str[character] < 'A' || str[character] > 'z') { - if (!space) { + if (!space && words != 0) { ++words; space = true; } - } else + } else { space = false; + if (words == 0) + ++words; + } }