Lecture 104
#include <iostream>
#include <conio.h>
using namespace std;
main ()
{
int charcnt=0;
int wordcnt=1;
char ch;
cout<<"Type in a phrase: \n";
while((ch=getche()) != '\r')
{
charcnt++;
if(ch==' ')
wordcnt++;
}
cout<<"\nCharacter count is :"<<charcnt;
cout<<"\nWord count is : "<<wordcnt;
getch();
return 0;
}
My name is shahid.
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10