i want to write a program to accept as an input numbers not more than 999 999 999 and out put in words say if x= 300 then cout<< three hundred
this is my solution hope it works
CODE
#include<iostream>
#include<cstring>
using namespace std;
void millions();
void thousands();
void hundreds();
int num,n,rec1,rec2,max,rec3[9],store,i,j,rec4[9];
char tenz[12][6]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
char out[100][6];
int main()
{
do
{
cout<<"Enter number of digits";
cin>>n;
}while(n>=9);
max=n;
for(i=0;i<n;i++)
{
cout<<"Enter numbers rec1["<<i+1<<"]:";
cin>>rec4[i];
}
for(i=0;i<max;i++)
{
store = rec4[i];
for(int x=0;x<=max;x++)
strcpy(out[i],tenz[store]);
}
i=0;
if (max>6)
millions();
else if (max>3)
thousands();
else
hundreds();
return 0;
}
void millions()
{
if (max==9)
{
cout<<out[i]<<"Hundred and "<<out[i++]<<"-ty "<<out[i+2]<<" millions,";
max=max-3;
i=i+3;
thousands();
}
else if (max==8)
{
cout<<out[i]<<"-ty "<<out[i+1]<<" millions,";
max=max-2;
i=i+2;
thousands();
}
else
{
cout<<out[i]<<" million,";
max = max-1;
i++;
thousands();
}
}
void thousands()
{
if (max==6)
{
cout<<out[i]<<" hundred and "<<" "<<out[i++]<<"-ty "<<out[i+2]<<" thousand, ";
max= max-3;
i=i+3;
hundreds();
}
else if (max==5)
{
cout<<out[i]<<"-ty"<<out[i+1]<<"thousand, ";
max=max-2;
i=i+2;
hundreds();
}
else
{
cout<<out[i]<<" thousand,";
max = max-1;
i++;
hundreds();
}
}
void hundreds()
{
if(max==3)
{
cout<<out[i]<<" hundred and "<<out[i++]<<"-ty "<<out[i+2];
}
else if(max==2)
{
cout<<out[i]<<"-ty "<<out[i++];
}
else
cout<<out[i];
}