Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Mathematics ProgramRSS Feeds

Program to covert a given Decimal Number into English Code

Posted By: Easy Tutor     Category: C++ Programming     Views: 2607

A C++ Program to covert a given Decimal Number into English Code.

Code for Program to covert a given Decimal Number into English Code in C++ Programming

 # include <iostream.h>
 # include <iomanip.h>
 # include <conio.h>
 # include <math.h>

 void english_code(longint);


 main( )
    {
       clrscr( );

       double number;

       cout<<"\n******************************************************************************"<<endl;
       cout<<"******************************************************************************"<<endl;
       cout<<"------------------------------------------------------------------------------"<<endl;
       cout<<"\n*****  Conversion of a number from Decimal Number System to English Code  ****"<<endl;
       cout<<"\n------------------------------------------------------------------------------"<<endl;
       cout<<"******************************************************************************"<<endl;
       cout<<"******************************************************************************"<<endl;

       gotoxy(1,22);
       cout<<"------------------------------------------------------------------------------"<<endl;
       cout<<"******************************************************************************"<<endl;
       cout<<"******************************************************************************";

       gotoxy(1,10);
       cout<<"\n\n ***  Enter the Decimal Number from ( -1000,0,00,000 --> +1000,0,00,000 )  ***\n\n\n"<<endl;
       cout<<setw(21)<<"Decimal Number ::  ";
       cin>>number;

       if((number>1000000000) || (number<-1000000000))
      cout<<"\n\n  Error ::  The given Decimal Number is out of range.";

       else
      {
         cout<<"\n\n  English  Code  ::   "<<endl;

         gotoxy(22,19);
         english_code(number);
      }

       getch( );

       return 0;
    }

 /*************************************************************************//*************************************************************************///------------------------  Function Definitions  -----------------------///*************************************************************************//*************************************************************************//*************************************************************************///------------------------  english_code(long int)  ---------------------///*************************************************************************/void english_code(longint number)
    {
       long number_1;
       long number_2;
       long number_3;
       long number_4;
       long number_5;
       long number_6;
       long number_7;
       long number_8;
       long number_9;
       long number_10;
       long number_11;
       long number_12;
       long number_13;
       long number_14;
       long number_15;
       long number_16;

       number_1=fabs(number);

       number_2=number_1/1000000;
       number_3=number_2/100;
       number_4=number_2%100;

       number_5=number_1%1000000;

       number_6=number_5/100000;
       number_7=number_5%100000;

       number_9=number_7/10000;
       number_10=number_7%10000;

       number_8=number_7/1000;
       number_11=number_10/1000;
       number_12=number_10%1000;

       number_13=number_12/100;
       number_14=number_12%100;

       number_15=number_14/10;
       number_16=number_14%10;

       if(number<0)
      cout<<" Minus ";

       if(number_2==1000)
      cout<<"One Thousand ";

       switch(number_3)
      {
         case 1 : cout<<"One Hundred ";
              break;

         case 2 : cout<<"Two Hundred ";
              break;

         case 3 : cout<<"Three Hundred ";
              break;

         case 4 : cout<<"Four Hundred ";
              break;

         case 5 : cout<<"Five Hundred ";
              break;

         case 6 : cout<<"Six Hundred ";
              break;

         case 7 : cout<<"Seven Hundred ";
              break;

         case 8 : cout<<"Eight Hundred ";
              break;

         case 9 : cout<<"Nine Hundred ";
              break;
      }

       if(number_4>=11 || number_4<=19)
      {
         if(number_4==11)
        cout<<"Eleven ";

         if(number_4==12)
        cout<<"Twelve ";

         if(number_4==13)
        cout<<"Thirteen ";

         if(number_4==14)
        cout<<"Fourteen ";

         if(number_4==15)
        cout<<"Fifteen ";

         if(number_4==16)
        cout<<"Sixteen ";

         if(number_4==17)
        cout<<"Seventeen ";

         if(number_4==18)
        cout<<"Eighteen ";

         if(number_4==19)
        cout<<"Nineteen ";
      }

       if(number_4<=10 || number_4>=20)
      {
         switch(number_4/10)
        {
           case 1 : cout<<"Ten ";
                break;

           case 2 : cout<<"Twenty ";
                break;

           case 3 : cout<<"Thirty ";
                break;

           case 4 : cout<<"Fourty ";
                break;

           case 5 : cout<<"Fifty ";
                break;

           case 6 : cout<<"Sixty ";
                break;

           case 7 : cout<<"Seventy ";
                break;

           case 8 : cout<<"Eighty ";
                break;

           case 9 : cout<<"Ninety ";
                break;
        }

         switch(number_4%10)
        {
           case 1 : cout<<"One ";
                break;

           case 2 : cout<<"Two ";
                break;

           case 3 : cout<<"Three ";
                break;

           case 4 : cout<<"Four ";
                break;

           case 5 : cout<<"Five ";
                break;

           case 6 : cout<<"Six ";
                break;

           case 7 : cout<<"Seven ";
                break;

           case 8 : cout<<"Eight ";
                break;

           case 9 : cout<<"Nine ";
                break;
        }
      }

       if(number_1>999999)
      cout<<"Million ";

       switch(number_6)
      {
         case 1 : cout<<"One Lac ";
              break;

         case 2 : cout<<"Two Lac ";
              break;

         case 3 : cout<<"Three Lac ";
              break;

         case 4 : cout<<"Four Lac ";
              break;

         case 5 : cout<<"Five Lac ";
              break;

         case 6 : cout<<"Six Lac ";
              break;

         case 7 : cout<<"Seven Lac ";
              break;

         case 8 : cout<<"Eight Lac ";
              break;

         case 9 : cout<<"Nine Lac ";
              break;
      }

       if(number_8>=10 || number_8<=19)
      {
         if(number_8==10)
        cout<<"Ten ";

         if(number_8==11)
        cout<<"Eleven ";

         if(number_8==12)
        cout<<"Twelve ";

         if(number_8==13)
        cout<<"Thirteen ";

         if(number_8==14)
        cout<<"Fourteen ";

         if(number_8==15)
        cout<<"Fifteen ";

         if(number_8==16)
        cout<<"Sixteen ";

         if(number_8==17)
        cout<<"Seventeen ";

         if(number_8==18)
        cout<<"Eighteen ";

         if(number_8==19)
        cout<<"Nineteen ";
      }

       if(number_8<10 || number_8>19)
      {
         switch(number_9)
        {
           case 2 : cout<<"Twenty ";
                break;

           case 3 : cout<<"Thirty ";
                break;

           case 4 : cout<<"Fourty ";
                break;

           case 5 : cout<<"Fifty ";
                break;

           case 6 : cout<<"Sixty ";
                break;

           case 7 : cout<<"Seventy ";
                break;

           case 8 : cout<<"Eighty ";
                break;

           case 9 : cout<<"Ninety ";
                break;
        }

         switch(number_11)
        {
           case 1 : cout<<"One ";
                break;

           case 2 : cout<<"Two ";
                break;

           case 3 : cout<<"Three ";
                break;

           case 4 : cout<<"Four ";
                break;

           case 5 : cout<<"Five ";
                break;

           case 6 : cout<<"Six ";
                break;

           case 7 : cout<<"Seven ";
                break;

           case 8 : cout<<"Eight ";
                break;

           case 9 : cout<<"Nine ";
                break;
        }
      }

       if(number>999 && number_8!=0)
      cout<<"Thousand ";

       if(number>99999)
      cout<<"\number_15\t\t";

       switch(number_13)
      {
         case 1 : cout<<"One Hundred ";
              break;

         case 2 : cout<<"Two Hundred ";
              break;

         case 3 : cout<<"Three Hundred ";
              break;

         case 4 : cout<<"Four Hundred ";
              break;

         case 5 : cout<<"Five Hundred ";
              break;

         case 6 : cout<<"Six Hundred ";
              break;

         case 7 : cout<<"Seven Hundred ";
              break;

         case 8 : cout<<"Eight Hundred ";
              break;

         case 9 : cout<<"Nine Hundred ";
              break;
      }

       if(number_14>=11 || number_14<=19)
      {
         if(number_14==11)
        cout<<"Eleven ";

         if(number_14==12)
        cout<<"Twelve ";

         if(number_14==13)
        cout<<"Thirteen ";

         if(number_14==14)
        cout<<"Fourteen ";

         if(number_14==15)
        cout<<"Fifteen ";

         if(number_14==16)
        cout<<"Sixteen ";

         if(number_14==17)
        cout<<"Seventeen ";

         if(number_14==18)
        cout<<"Eighteen ";

         if(number_14==19)
        cout<<"Nineteen ";
      }

       if(number_14<=10 || number_14>=20)
      {
         switch(number_15)
        {
           case 1 : cout<<"Ten ";
                break;

           case 2 : cout<<"Twenty ";
                break;

           case 3 : cout<<"Thirty ";
                break;

           case 4 : cout<<"Fourty ";
                break;

           case 5 : cout<<"Fifty ";
                break;

           case 6 : cout<<"Sixty ";
                break;

           case 7 : cout<<"Seventy ";
                break;

           case 8 : cout<<"Eighty ";
                break;

           case 9 : cout<<"Ninety ";
                break;
        }

         switch(number_16)
        {
           case 1 : cout<<"One ";
                break;

           case 2 : cout<<"Two ";
                break;

           case 3 : cout<<"Three ";
                break;

           case 4 : cout<<"Four ";
                break;

           case 5 : cout<<"Five ";
                break;

           case 6 : cout<<"Six ";
                break;

           case 7 : cout<<"Seven ";
                break;

           case 8 : cout<<"Eight ";
                break;

           case 9 : cout<<"Nine ";
                break;
        }
      }

       if(number==0)
      cout<<"Zero ";
    }
  
Share: 


Didn't find what you were looking for? Find more on Program to covert a given Decimal Number into English Code Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to covert a given Decimal Number into English Code is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!