This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2024_Stanislav_Mykhailenko/Lesson_2/Task_4/main.cpp
Stanislav Mykhailenko bdf1b02fc4
Fix Lesson 2 Task 4
2024-07-20 15:26:07 +03:00

30 lines
596 B
C++

#include <iostream>
using namespace std;
int main()
{
char str[256];
cout << "Enter some string: ";
cin.getline(str, 256);
int words = 0;
bool space = false;
for (int character = 0; str[character] != 0; ++character) {
if (str[character] < 'A' || str[character] > 'z') {
if (!space && words != 0) {
++words;
space = true;
}
} else {
space = false;
if (words == 0)
++words;
}
}
cout << "Number of words: " << words << endl;
return 0;
}