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>
#include <math.h>
using namespace std;
int main()
{
string text;
cout<<"Enter string: ";
getline(cin,text);
int count=0;
int i=0;
do{
if(text[i]!=' ' && text[i]!='#'){
count++;
}
i++;
}while(text[i]!='#');
cout<<"The number of characters: "<<count<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment