Hello Daniweb IT Community, this is the somehow my code for this problem of mine.
My only problem would be in the portion of getting the cents and the Billion it just because of the limitation of the long datatype?
I really need some opinions on how I can solve this problem. Thank you.!!!
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void pw(long,char[]);
char *one[]={" "," One"," Two"," Three"," Four"," Five"," Six",
" Seven","Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen",
"Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"};
char *ten[]={" "," "," twenty"," Thirty"," Forty"," Fifty"," Sixty",
"Seventy"," Eighty"," Ninety"};
void *centavos(int,char[]);
char *cents[]={" "," One"," Two"," Three"," Four"," Five"," Six",
" Seven","Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen",
"Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"};
char *tencents[]={" "," "," twenty"," Thirty"," Forty"," Fifty"," Sixty",
"Seventy"," Eighty"," Ninety"};
long n;
//int cp;
char *num, *cp;
char* c,d;
void main()
{
clrscr();
printf("Enter any 9 digit no: ");
gets(num);
while( (c=strchr(num,',')) > 0)
{
memmove(c,c+1,strlen(c-1));
}
n=atol(num);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
//pw((n/1000000000),"Billion");
pw((n/100000000),"Hundred");
pw(((n/1000000)%100),"Million");
pw(((n/100000)%100),"Hundred");
pw(((n/1000)%100),"Thousand");
pw(((n/100)%10),"Hundred");
pw((n%100)," ");
}
if((strchr(num,'.')!=0))
{
int cpr,com,hab,con;
cp = strchr(num,'.');
com = cp-num;
hab = strlen(num);
for (cpr=com+1; cpr<=hab;cpr++)
printf("%c",num[cpr]);
//x=num[cpr];
//printf("%c",x);
//con=atoi(num[cpr]);
//centavos((num[cpr]%100)," ");
printf("Print if my decimal");
}
getch();
}
void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}
/*void centavos(int cents,char hc[])
{
(n>19)?printf("%d %d ",tencents[n/10],cents[n%10]):printf("%f ",cents[n]);
if(n)printf("%s ",hc);
} */