I'm a newbie in programing and I'm having hard time on it.
Please help me in my project that when i enter a number it gives a word form on it. ratio 1-10,000
Example Output 1:
Enter Number: 2
two
Example Output 2:
Enter Number: 24
twenty four
Example Output 3:
Enter Number: 10000
ten thousand
Please i really need your help with this.
Thank you very much and God bless you!
Comments
#include
#define QCSNW 1024
int convertDToW(int nd,char snw[]);
int convertDToW123(int nd,char snw[]);
int convertDToW12(int nd,char snw[]);
void main()
{
int nd;
char snw[QCSNW];
for(;;)
{
printf("Enter number (1 - 10000):");
scanf("%d",&nd);
if(nd==0)
break;
convertDToW(nd,snw);
printf("%s
",snw);
}
}
int convertDToW(int nd,char snw[])
{
int ires;
int ndth;
char snwk[QCSNW];
strcpy(snw,"");
ires=1;
if(1<=nd&&nd<=10000)
{
ndth=nd/1000;
convertDToW123(ndth,snwk);
if(strcmp(snwk,""))
{
strcpy(snw,snwk);
strcat(snw," thousand");
}
ndth=nd%1000;
convertDToW123(ndth,snwk);
if(strcmp(snw,""))
strcat(snw," ");
strcat(snw,snwk);
}
else
ires=0;
return ires;
}
int convertDToW123(int nd,char snw[])
{
int ires;
int nd2r,nh;
char snwk[QCSNW];
strcpy(snw,"");
ires=1;
if(0<=nd&&nd<1000)
{
nd2r=nd%100;
nh=nd/100;
convertDToW12(nh,snwk);
if(strcmp(snwk,""))
{
strcpy(snw,snwk);
strcat(snw," hundred");
}
convertDToW12(nd2r,snwk);
if(strcmp(snw,""))
strcat(snw," ");
strcat(snw,snwk);
}
else
ires=0;
return ires;
}
int convertDToW12(int nd,char snw[])
{
int ires;
int nd2,nd1;
char snwk[QCSNW];
strcpy(snw,"");
ires=1;
if(0<=nd&&nd<100)
{
switch(nd)
{
case 0:
strcpy(snw,"");
break;
case 1:
strcpy(snw,"one");
break;
case 2:
strcpy(snw,"two");
break;
case 3:
strcpy(snw,"three");
break;
case 4:
strcpy(snw,"four");
break;
case 5:
strcpy(snw,"five");
break;
case 6:
strcpy(snw,"six");
break;
case 7:
strcpy(snw,"seven");
break;
case 8:
strcpy(snw,"eight");
break;
case 9:
strcpy(snw,"nine");
break;
case 10:
strcpy(snw,"ten");
break;
case 11:
strcpy(snw,"eleven");
break;
case 12:
strcpy(snw,"twelve");
break;
case 13:
strcpy(snw,"thirteen");
break;
case 14:
strcpy(snw,"fourteen");
break;
case 15:
strcpy(snw,"fifteen");
break;
case 16:
strcpy(snw,"sixteen");
break;
case 17:
strcpy(snw,"seventeen");
break;
case 18:
strcpy(snw,"eightteen");
break;
case 19:
strcpy(snw,"nineteen");
break;
default:
nd2=nd/10;
nd1=nd-nd2*10;
switch(nd2)
{
case 2:
strcpy(snw,"twenty");
break;
case 3:
strcpy(snw,"thirty");
break;
case 4:
strcpy(snw,"forty");
break;
case 5:
strcpy(snw,"fifty");
break;
case 6:
strcpy(snw,"sixty");
break;
case 7:
strcpy(snw,"seventy");
break;
case 8:
strcpy(snw,"eightty");
break;
case 9:
strcpy(snw,"ninety");
break;
}
convertDToW12(nd1,snwk);
if(strcmp(snwk,""))
{
strcat(snw," ");
strcat(snw,snwk);
}
break;
}
}
else
ires=0;
return ires;
}