itsshivamku / CPP-Programming

C++ Programming Projects
0 stars 0 forks source link

WORD COUNT using C++ Programming #3

Open itsshivamku opened 1 year ago

itsshivamku commented 1 year ago

include

include

include

using namespace std;

int countWords(const string& input) { stringstream ss(input); string word; int count = 0;

while (ss >> word) {
    count++;
}

return count;

}

int main() { cout << "Word Count Program\n";

string input;
cout << "Enter a sentence or paragraph: ";
getline(cin, input);

int wordCount = countWords(input);
cout << "Number of words: " << wordCount << endl;

return 0;

}