Idea

Thread Solved
Reply

Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Idea

 
0
  #1
Jun 26th, 2009
I m trying to find idea to change like from 1 to one and 2 to two and 3 three from 1 to 999 i m had an idea to do like a string with information etc ? but i want better idea so i dunno how to do it lolz.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Idea

 
0
  #2
Jun 26th, 2009
Think Check Writing Program
  1. ary [] = { Zero, One, ...., Nineteen Twenty, Thirty, Fourty, ... Ninety, Hundred, Thousand };
  2.  
  3. if (n <= 19)
  4. ary[n]
  5. else if (n < 100) // 20...99
  6. j = ary[ (n / 10) + 18 ] // Get 10's
  7. k = ary[ n % 10 ] // get 1's if zero ignore
  8. if ( k == 0) then ignore
  9.  
  10. etc.
Last edited by wildgoose; Jun 26th, 2009 at 7:23 pm. Reason: corrections
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,522
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 189
BestJewSinceJC BestJewSinceJC is online now Online
Posting Virtuoso

Re: Idea

 
0
  #3
Jun 26th, 2009
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.
I am so hungry. :(
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Idea

 
0
  #4
Jun 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Re: Idea

 
0
  #5
Jun 26th, 2009
but i still i would have to do tests from 1 to nineteen
whish would be alot of tests i thought of this idea but is there another way i could do it by
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Idea

 
0
  #6
Jun 26th, 2009
No, For a number up to 999 you have 4 tests?

If number is 0 to 20 then use it as a string table index.
if greater then that then turn it into 10's and 1's
And use them as separate indexes!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Idea

 
0
  #7
Jun 26th, 2009
  1. char *szNoun[]= {
  2. "zero", "one", "two", "three", "four", "five", "six", "seven",
  3. "eight", "nine", "ten",
  4. "eleven", "twelve", "thirteen", "fourteen", "fifteen",
  5. "sixteen", "seventeen", "eighteen", "nineteen",
  6. "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
  7. "eighty", "ninety", "hundred", "thousand" };
  8.  
  9. // n is number
  10. if ( n <= 20)
  11. print szNoun[ n ];
  12. else if (n < 100)
  13. j = n / 10; // { 2...9 }
  14. k = n % 10; // { 0...9 }
  15. print szNoun[ j + 18 ];
  16. if ( k != 0 )
  17. print "-" szNoun[k];
  18.  
  19. // and the rest for you to figure out!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Re: Idea

 
0
  #8
Jun 26th, 2009
till now i made but i tried with 21 it didnt work out
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define DEBUG
  4. char *string[]= {
  5. "zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen","fifteen",
  6. "sixten","sevten","eighteen","nineteen"
  7. };
  8. char *string2[]= {
  9. "twenty","thirty","fourty","fifty","sexty","seventy","eighty","nighty","hundreed"
  10. };
  11. //from int to array and return char string
  12. char *IntToarray(int num)
  13. {
  14. char *pch;
  15. int j=0;
  16. if(num>0 || num<=19)
  17. pch=string[num];
  18. else if(num>=20 || num<=100) {
  19. j=num %10;
  20. #ifdef DEBUG
  21. printf("number of j is %d",j);//it should out here 1 and it didnt
  22. printf("number of j is %d",j);
  23. if(j==1)
  24. puts("dude so cool");
  25. #endif
  26. getchar();
  27. num=num %10;
  28. strcat(string2[num]," ");
  29. strcat(string2[num],string[j]);
  30. }
  31. }
  32. int main(void)
  33. {
  34. char *pch;
  35. pch=IntToarray(21);
  36. //puts(pch);
  37. getchar();
  38. return 0;
  39. }
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 212
Reputation: MrNoob has a little shameless behaviour in the past 
Solved Threads: 6
MrNoob's Avatar
MrNoob MrNoob is offline Offline
Posting Whiz in Training

Re: Idea

 
0
  #9
Jun 26th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Idea

 
0
  #10
Jun 26th, 2009
You really need the dwarf array for optimization.
you have a math bug.
  1. char szBuf[ 80 ];
  2. strcpy( szBuf, string1[ num ];
  3.  
  4. else if(num>=20 || num<100) {
  5. j=num %10;
  6. #ifdef DEBUG
  7. printf("number of j is %d",j);//it should out here 1 and it didnt
  8. printf("number of j is %d",j);
  9. if(j==1)
  10. puts("dude so cool");
  11. #endif
  12. getchar();
  13. num=num / 10;
  14. strcpy( szBuf, string2[ num ] );
  15. if (j)
  16. {
  17. strcat( szBuf, "-" );
  18. strcat( szBuf, string1[ j ] );
  19. }
  20. }
  21.  
  22. printf szBuf
Last edited by wildgoose; Jun 26th, 2009 at 9:47 pm. Reason: correction
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC