Syvum Home Page

Home > Quiz Games > C++ Programming > Print Preview

C++ Programming : Program 27-A

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();
}

This program takes in a sentence as a screen input from the user.
It then determines the number of words and characters in the sentence using the 'WHILE' loop and outputs them using the 'cout' command.

this is a nice program

Words = 5
Characters = 18

Index of C++ Programs
 

-
-
 
45 more pages in C++ Programming

Contact Info © 1999-2017 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright