Tuesday, December 5, 2017

C++ Code Review: Shows how many words an entered sentence has.

Description: This program shows how many words an entered sentence has.

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program shows how many words an entered sentence has.

 

#include<iostream>

#include<stdio.h>

 

using namespace std;

 

int main()

{

    char a[100];

    int i,count=1;

 

    cout<<"Enter a string:";

    gets(a);

 

    for(i=0;a[i]!='\0';++i)

    {

        if(a[i]==' ')

            count++;

    }

 

    cout<<"\nThere are "<<count<<" words in the given string";

 

    return 0;

}        

 Output:

 clip_image002

If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment