Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Manume/3c1f0a7d90e7e84ed00c to your computer and use it in GitHub Desktop.
Save Manume/3c1f0a7d90e7e84ed00c to your computer and use it in GitHub Desktop.
Program to count the number of words and characters in a sentence
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int countch=0;
int countwd=1;
cout << "Enter your sentence in lowercase: " << endl;
char ch='a';
while(ch!='\r')
{
ch=getche();
if(ch==' ')
countwd++;
else
countch++;
}
cout << "\n Words = " << countwd << endl;
cout << "Characters = " << countch-1 << endl;
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment