Pages

Subscribe:

About Template

Random Posts

C++ Program That Counts The Number Of Letters In A Word


Name:  Number of Letters in a Word
Description of the Program: This program tally how many a letter has in a given word.


As you can see in the screenshot below, I entered the word Bourgeoisie,then, it tallied how many letter B,e,g,i,o,r,s, and u in this word. Just make it sure, you put a dot or period sign after you enter any word.



//Below are the Codes of the Program:
#include<iostream.h>
#include<conio.h>
void swap (char& a, char& b)
    {
        char c,d;
           c=a;
               d=b;
           a=d;
         b=c;
    }


int main()
{     char name[20];
    int t[20]={0},c=0,count=0,con[10]={0},z=0;
   cout<<"When you enter any word be sure it has a '.' at the end.\n";
   cout<<"Example: Mississippi. \n";
    cout<<"\n\Enter any word: ";

cin>>name;

     for(int d=0;d<20;d++)
     {
     if(name[d]=='.')
       d=20;

     else count++;

    }


      for(int g=0;g<count;g++)
 {
          for(int e=0;e<count;e++)
      {
        if((e+1)<count)
              {
                  if (name[e]>name[e+1])
                  swap(name[e],name[e+1]);
               }
      }
   }


 for(int f=0;f<count;f++)
 if(name[f]!=name[f+1])
{

 cout<< name[f];
  for(int fa=0;fa<count;fa++)
  {
  if(name[f]==name[fa])
   con[z]++;

  }

  cout<<"\t"<< con[z]<<"\n";
  z++;
}

 getch();
}