C++ program to enter a number and print it into words

C++ program to enter a number and print it into words

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

void once(int a)
{
switch(a)
{
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;
}
}

int tens(int a,int b)
{
int flag=0;
switch(a)
{
case 1:
flag=1;
switch(b)
{
case 0: cout<<“Ten”;
break;
case 1: cout<<“Eleven”;
break;
case 2: cout<<“Twelve”;
break;
case 3: cout<<“Thirteen”;
break;
case 4: cout<<“Fourteen”;
break;
case 5: cout<<“Fifteen”;
break;
case 6: cout<<“Sixteen”;
break;
case 7: cout<<“Seventeen”;
break;
case 8: cout<<“Eighteen”;
break;
case 9: cout<<“Nineteen”;
break;
}
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;
}
return(flag);
}

void hundred(int a)
{
switch(a)
{
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;
}
}

void main()
{
clrscr();
int n,a[3],i=0,flag=0;
cout<<“Enter any number(max 3 digits):”;
cin>>n;

while(n!=0)
{
a[i++]=n%10;
n=n/10;
}

for(i=i-1;i>=0;–i)
{
if(i==0&&flag==0)
once(a[0]);
if(i==1)
flag=tens(a[1],a[0]);
if(i==2)
hundred(a[2]);
cout<<” “;
}
getch();
}

13 thoughts on “C++ program to enter a number and print it into words”

  1. #include
    #include
    #include

    class CH_W
    {
    int value;
    public:
    CH_W();
    void Word(int);
    void Tens(int,int);
    };

    CH_W::CH_W()
    {
    cout<<"nEnter The No.(Max 3 digit)t";
    cin>>value;
    if(value<10)
    {
    Word(value);
    }
    else if(value<100)
    {
    Tens(abs(value/10),value%10);
    if(value/10!=1)
    Word(value%10);
    }
    else
    {
    Word(abs(value/100));
    cout<<" Hundred";
    Tens((abs(value/10))%10,(value%100)%10);
    if(abs((value%100)/10)!=1)
    Word((value%100)%10);
    }
    }

    void CH_W::Word(int value)
    {
    switch(value)
    {
    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;
    }
    }

    void CH_W::Tens(int value1,int value2)
    {
    switch (value1)
    {
    case 1:
    {
    switch(value2)
    {
    case 1: cout<<" Elaven";
    break;
    case 2: cout<<" Twel";
    break;
    case 3: cout<<" Thirteen";
    break;
    case 4: cout<<" Fourteen";
    break;
    case 5: cout<<" Fifteen";
    break;
    case 6: cout<<" Sixteen";
    break;
    case 7: cout<<" Seventeen";
    break;
    case 8: cout<<" Eighteen";
    break;
    case 9: cout<<" Ninteen";
    break;
    }
    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<<" Ninty";
    break;
    }
    }

    void main()
    {
    clrscr();
    CH_W o;
    getch();
    }

    1. Neeraj Mishra your 100% correct….. My suggestion also same. Why you want to work under somebody, work as freedom . Get jobs from freelancer sites and develop by your own.

  2. and this is from me 🙂

    # include
    # include

    main()
    {
    int xyz,x,y,z;

    printf("3 basamakli Sayiyi giriniz:");
    scanf("%d",&xyz);
    z= xyz%10;
    y= ((xyz – z)/10)%10;
    x= (((xyz-(y*10))-z)/100);

    if(x!=0)
    {
    switch(x)
    {

    case 1:
    printf("");
    break;
    case 2:
    printf("iki");
    break;
    case 3:
    printf("uc");
    break;
    case 4:
    printf("dort");
    break;
    case 5:
    printf("bes");
    break;
    case 6:
    printf("alti");
    break;
    case 7:
    printf("yedi");
    break;
    case 8:
    printf:("sekiz");
    break;
    case 9:
    printf("dokuz");
    break;

    }
    printf(" yuz ");
    switch(y)
    {
    case 1:
    printf("on ");
    break;
    case 2:
    printf("yirmi ");
    break;
    case 3:
    printf("otuz ");
    break;
    case 4:
    printf("kirk ");
    break;
    case 5:
    printf("elli ");
    break;
    case 6:
    printf("altmis ");
    break;
    case 7:
    printf("yetmis ");
    break;
    case 8:
    printf("seksen ");
    break;
    case 9:
    printf("doksan ");
    break;
    }
    switch(z)
    {
    case 0:
    printf("");
    break;
    case 1:
    printf("bir");
    break;
    case 2:
    printf("iki");
    break;
    case 3:
    printf("uc");
    break;
    case 4:
    printf("dort");
    break;
    case 5:
    printf("bes");
    break;
    case 6:
    printf("alti");
    break;
    case 7:
    printf("yedi");
    break;
    case 8:
    printf("sekiz");
    break;
    case 9:
    printf("dokuz");
    break;

    }
    }
    else {

    printf("Sayi Uc Basamakli Degildir");
    }
    getchar();

    return 0;

    }

  3. Todd Goodfellow

    You will develop a C++ program to spell out numbers given in a file. Assume that you have text file appears as

    15
    -568
    3432
    9001
    16045

    Input file has one number (short) (minus or plus or zero) at each line. A number can have at most 5 characters, such as 12356, or -1245. For the above file, your program should generate

    fifteen
    minus five hundred sixty eight
    three thousand four hundred sixty two
    nine thousand one
    sixteen thousand forty five


    I should use function short, which is a number read from file, and returns a string, which is spelling out of number, i.e., the prototype seems like

    string Spell (short a);

    can some one please help?

  4. I want a c++ program using switch case structure to display the given number in words.(between 1 and 9).please HELP!!!

  5. #include
    using namespace std;
    void expand(int);
    int main()
    {
    int num;
    cout<>num;
    expand(num);
    }
    void expand(int value)
    {
    const char * const ones[20] = {“zero”, “one”, “two”, “three”,”four”,”five”,”six”,”seven”,
    “eight”,”nine”,”ten”,”eleven”,”twelve”,”thirteen”,”fourteen”,”fifteen”,”sixteen”,”seventeen”,
    “eighteen”,”nineteen”};
    const char * const tens[10] = {“”, “ten”, “twenty”, “thirty”,”forty”,”fifty”,”sixty”,”seventy”,
    “eighty”,”ninety”};

    if(value<0)
    {
    cout<=1000)
    {
    expand(value/1000);
    cout<<" thousand";
    if(value % 1000)
    {
    if(value % 1000 < 100)
    {
    cout << " and";
    }
    cout <= 100)
    {
    expand(value / 100);
    cout<<" hundred";
    if(value % 100)
    {
    cout <= 20)
    {
    cout << tens[value / 10];
    if(value % 10)
    {
    cout << " ";
    expand(value % 10);
    } }
    else
    {
    cout<<ones[value];
    }
    return;
    }

  6. .Please write a program that asks a user for a three-digit number, then prints the English word for the number: 150
    please someone help me i need code for this

Leave a Comment

Your email address will not be published. Required fields are marked *