| | |
Idea
Thread Solved
![]() |
Think Check Writing Program
C Syntax (Toggle Plain Text)
ary [] = { Zero, One, ...., Nineteen Twenty, Thirty, Fourty, ... Ninety, Hundred, Thousand }; if (n <= 19) ary[n] else if (n < 100) // 20...99 j = ary[ (n / 10) + 18 ] // Get 10's k = ary[ n % 10 ] // get 1's if zero ignore if ( k == 0) then ignore etc.
Last edited by wildgoose; Jun 26th, 2009 at 7:23 pm. Reason: corrections
•
•
Join Date: Sep 2008
Posts: 1,522
Reputation:
Solved Threads: 189
What the poster above posted might look confusing, but what he is saying is a good way of doing this: Each String in the array will be the "name" of the index it is at. So index 0 of the array is named zero, and so on. This means in order to find the name of "20", you would use array[20] and it would return "twenty" since that is what you stored there.
The implementation is a little different - for example in C, I think an array of Strings is actually a 2D array of chars, but you get the point, I hope.
The implementation is a little different - for example in C, I think an array of Strings is actually a 2D array of chars, but you get the point, I hope.
I am so hungry. :(
Ah, 20 was on the edge, but 21 would involve hitting the list twice.
Once for "twenty" and again for "one" then glue the two halves together for "twenty-one"
30 would be "thirty" since no ones remainder on the modulus then no second noun.
134 would be "One" + "Hundred" "Thirty" - "Four"
So twenty-seven ASCII nouns would cover one thousand numbers.
Once for "twenty" and again for "one" then glue the two halves together for "twenty-one"
30 would be "thirty" since no ones remainder on the modulus then no second noun.
134 would be "One" + "Hundred" "Thirty" - "Four"
So twenty-seven ASCII nouns would cover one thousand numbers.
C Syntax (Toggle Plain Text)
char *szNoun[]= { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred", "thousand" }; // n is number if ( n <= 20) print szNoun[ n ]; else if (n < 100) j = n / 10; // { 2...9 } k = n % 10; // { 0...9 } print szNoun[ j + 18 ]; if ( k != 0 ) print "-" szNoun[k]; // and the rest for you to figure out!
till now i made but i tried with 21 it didnt work out
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #define DEBUG char *string[]= { "zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen","fifteen", "sixten","sevten","eighteen","nineteen" }; char *string2[]= { "twenty","thirty","fourty","fifty","sexty","seventy","eighty","nighty","hundreed" }; //from int to array and return char string char *IntToarray(int num) { char *pch; int j=0; if(num>0 || num<=19) pch=string[num]; else if(num>=20 || num<=100) { j=num %10; #ifdef DEBUG printf("number of j is %d",j);//it should out here 1 and it didnt printf("number of j is %d",j); if(j==1) puts("dude so cool"); #endif getchar(); num=num %10; strcat(string2[num]," "); strcat(string2[num],string[j]); } } int main(void) { char *pch; pch=IntToarray(21); //puts(pch); getchar(); return 0; }
i dunno how its possible to do it with 1 string only like if i get 20 or thirty fourty fifty etc etc i think that should be in a array itself so i get the reminder by j then after that cancnate it to the string2
then as for 100 and up i have to do extra work but i will figure that out i just wanna fix from 20 to 99 first then do from 100 to 999
then as for 100 and up i have to do extra work but i will figure that out i just wanna fix from 20 to 99 first then do from 100 to 999
You really need the dwarf array for optimization.
you have a math bug.
you have a math bug.
C Syntax (Toggle Plain Text)
char szBuf[ 80 ]; strcpy( szBuf, string1[ num ]; else if(num>=20 || num<100) { j=num %10; #ifdef DEBUG printf("number of j is %d",j);//it should out here 1 and it didnt printf("number of j is %d",j); if(j==1) puts("dude so cool"); #endif getchar(); num=num / 10; strcpy( szBuf, string2[ num ] ); if (j) { strcat( szBuf, "-" ); strcat( szBuf, string1[ j ] ); } } printf szBuf
Last edited by wildgoose; Jun 26th, 2009 at 9:47 pm. Reason: correction
![]() |
Similar Threads
- Good Idea - Bad Brain! (Software Development Job Offers)
- What is the best project idea! (Computer Science)
- I need an idea about my FYP (IT Professionals' Lounge)
- IDEA :: Make Notes in Internet Explorer (Web Browsers)
Other Threads in the C Forum
- Previous Thread: socket programming error
- Next Thread: help with output file from screen to csv file
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi




lolz. 

