Created
May 21, 2014 10:32
-
-
Save Manume/3c1f0a7d90e7e84ed00c to your computer and use it in GitHub Desktop.
Program to count the number of words and characters in a sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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