Answer to Question #221207 in Programming & Computer Science for Den

Question #221207
How do I do code for the number of words in a sentence
1
Expert's answer
2021-07-29T03:06:37-0400
#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;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS