#include <iostream>
using namespace std;
int main() {
char sentence[500];
cout << "Enter a sentence: ";
cin.getline(sentence,500);
int numberWords = 0;
for(int i = 0; sentence[i] != '\0'; i++)
{
if (sentence[i] == ' '){
numberWords++;
}
}
numberWords++;
cout << "The number of words: " << numberWords << endl;
cin>>numberWords;
return 0;
}
Comments
Leave a comment