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.
#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;
}
Comments
Leave a comment