Created
March 25, 2026 08:07
-
-
Save juanfal/97f155911d91ae16ba8ca1244d477663 to your computer and use it in GitHub Desktop.
count words to . all in main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // t04e21.numwords.cpp | |
| // juanfc 2026-03-25 | |
| // | |
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int wordCount = 0; | |
| bool inWord = false; | |
| char c; | |
| while (cin.get(c) and c != '.') { | |
| if (c != ' ' and not inWord) { | |
| wordCount++; | |
| inWord = true; | |
| } else if (c == ' ') { | |
| inWord = false; | |
| } | |
| } | |
| cout << wordCount << " words" << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment