Ok.
First: Create these string-arrays, for example with
Code:char one[3][5]={"zero","one","two"}; // HORRIBLE! :D //test: printf("%s",one[1]);
Second: get the digits, as suggested, of your number, for example
Be careful if the number after the "hundreds"-step is smaller than 20 -> additional cases.Code:... thousands=int(your_number)/1000; your_number-=1000*thousands; ... hundreds=int(your_number)/100 ; your_number-=100*hundreds; ...
Third: Print out according to the way you want to present the number
for example with
Code:... if (thousands!=0) printf("... %s thousand\t",ones[thousands]); if (hundredss!=0) printf("... %s hundred\t",ones[hundreds]); ...
Remark: this is all c.
/edit:about your problem: 99000
you can solve it writing a recursive function print_the_number:
where print_the_number is again the same function with whichCode:... if (thousands!=0) printf("... %s thousand\t",print_the_number(thousands)); ...
you initially wanted to print your starting number (recursive approach).




Reply With Quote