Answer to Question #289971 in C++ for ali

Question #289971

Create a program that uses a do-while loop to count the number of characters (not including whitespace) entered by the user. The count should end when it first encounters a # character in the input. 


1
Expert's answer
2022-01-29T15:59:56-0500
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string line;
	cout << "Please, enter a string: ";
	getline(cin, line, '#');
	int wordCount=0;
	int i = 0;
	do
	{
		if (line[i] != ' '&&line[i] != '\t'&&line[i] != '\n')
		{
			wordCount++;
		}
		i++;
	} while (i<line.size());
	cout << "The number of characters is " << wordCount;
}	

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