c++

Convert Number To Words C++

Convert Number To Words

C++


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

int ten(char a,char b)
{

int c;
c=1;

switch(a)
{

case '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<<"Eightteen ";
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;

default:
c=0;
break;
}

return c;
}

int one(char a)
{

int b;
b=1;

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;

default:
b=0;
break;
}

return b;
}

int main()
{

char a[13];
int i,w1,w2,w3;

clrscr();
cout<<"Enter A Number -> ";
cin>>a;

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

if(i>12)
{
cout<<"The Number Is Too Long!";
goto end;
}

if(i==1 && a[0]=='0')
{
cout<<"Zero";
goto end;
}

w1=one(a[i-12]);
if(w1==1)
cout<<"Hundred ";

w2=ten(a[i-11],a[i-10]);

if(a[i-11]!='1')
w3=one(a[i-10]);

if(w1==1 || w2==1 || w3==1)
cout<<"Billion ";

w1=one(a[i-9]);
if(w1==1)
cout<<"Hundred ";

w2=ten(a[i-8],a[i-7]);

if(a[i-8]!='1')
w3=one(a[i-7]);

if(w1==1 || w2==1 || w3==1)
cout<<"Million ";

w1=one(a[i-6]);
if(w1==1)
cout<<"Hundred ";

w2=ten(a[i-5],a[i-4]);

if(a[i-5]!='1')
w3=one(a[i-4]);

if(w1==1 || w2==1 || w3==1)
cout<<"Thousand ";

w1=one(a[i-3]);
if(w1==1)
cout<<"Hundred ";

w2=ten(a[i-2],a[i-1]);

if(a[i-2]!='1')
w3=one(a[i-1]);

end:
getch();
return 0;
}