very will said ChaosOrb... walay gamit kung dili gyud masabtan....
i learned something with this discussion... naanad man gud mi sa C++.... ganahan ko mag learn sa C....
nindot na daghan ta mahibaw-an....
very will said ChaosOrb... walay gamit kung dili gyud masabtan....
i learned something with this discussion... naanad man gud mi sa C++.... ganahan ko mag learn sa C....
nindot na daghan ta mahibaw-an....
very will said ChaosOrb... walay gamit kung dili gyud masabtan....
i learned something with this discussion... naanad man gud mi sa C++.... ganahan ko mag learn sa C....
nindot na daghan ta mahibaw-an....
@ChaosOrb any new release version? hehehe...
on the program you post... there is much simplier I guess, using for loop and arrays only. there's an excellent technique or pattern to solve the problem...with a minimum coding.
mga choi.... if mka sugat gani mo ug thread like this... mga assignment threads ba... be like silent-kill..... dont give him what he wants.... instead, make him get what he wants... d ta mu spoon feed oi... kay magka degrade nya ang mga future programmers diri sa pinas... hehehe... samot na karon na naa na'y .NET framework... magkatapolan na jud mga programmers ani... heheh...
@silent-kill
bai hold ur ground... sakto imo principle na d nmu i hatag ang precise and exact code....they have their own brains... let them use it... dont let them use ours....................... coz its not free... hahahahah....
here is my code ic C.
variables:
int num;
int tens; //these for your variable ranging ten.
if (num>19 && <=99)
{
tens = num/10;
num = num% 10;
switch(tens)
{
case 2:
{
printf("Twenty");
break;
}
case 3:
{
printf("Thirty");
break;
}
case until 9 for ninety...
}
}
int num,
if(num>=1 && num <=19)
{
switch(num)
{
case 1:
{
printf("One");
break;
}
case 2:
{
printf("Two");
break;
}
.
.
.
until case 19:
}
Kung imong padayuno imong input pataas. ipababaw lang ang code, example imong input >=20 up to 99
kung padayunon pagyud nimo pataas ang imong input mag declare lang ka ug variable for
hundreds,thousand, hundredthousand, million and soon, then change the division /number and modulo % as you can see in tens...
hope this will help.... good luck.....
Here's my step by step formula...
1. Make an array:
char *ones[10] = {"", "one ","two ","three ","four ", "five ",
"six ","seven ","eight ","nine "};
for Tens do this: "ten ","eleven ","twelve ","thirteen ", "fourteen ", "fifteen ","sixteen ","seventeen ","eighteen ","nineteen "
for twenties do this: "","","twenty ","thirty ","forty ", "fifty ","sixty ","seventy ","eighty ","ninety "
for thousands or millions do this: "","thousand ","million ", "billion "......
Note: put spaces at the end of the word, just leave the first index empty in "ones" and two index empty in "twenties". Glad if you figure it out why. Especially why we not included "Hundred" you can see sample output below.
2. Convert the user input into string... I used sprintf functions. your goal on this level is to break the string by "3" if the user input 45,310. You should have two separated variable that holds "45" and "310". Think about another array this time.
constMIN = 3 (of course we want to break every 3 digits)
constMAX = maximum 0's in your program you can even make it until vigintillion if you want.
Just figure it out what the purpose of my conditional statement "-1" and "-2"Code:for(i=constMIN; i<constMAX; i=i+constMIN){ len = strlen(strVal); if ((len - i) < -2) break; else if ((len - i) >= 0){ save something here... } } else if ((len - i) >= -1){ do something here } else if ((len - i) >= -2){ do something here } else break; }
3. String Manipulation. Just use a simple for loop. no need any switch or many if if if if if if if if else else statements.... take note what's inside of your array here. it can be integer or a character. at step 2. I directly converted the number back to integer.
clue:
a. User input was "254,310"
b. We break this into two part {2,5,4} and {3,1,0}
c. Using for loop..... this would be....
next on the code above are just plain if statements...Code:for loop ...where we read the number X var1 = x % 10 var2 = .. 100 and 10 being use here. var3 = .. 1000 and 100 being use here. if (x == 0) continue # of course
Tens[2] + ones[5] + "hundred" + and so on.... you will only add the string "hundred" to a specific condition. where var3 is greater than 0.
important output to analyze from my previous post:
seven hundred ninety two
seven hundred ninety four
seven hundred ninety six
seven hundred ninety eight
eight hundred
eight hundred two
eight hundred four
eight hundred six
eight hundred eight
eight hundred ten
eight hundred twelve
eight hundred fourteen
eight hundred sixteen
eight hundred eighteen
eight hundred twenty
eight hundred twenty two
eight hundred twenty four
eight hundred twenty six
eight hundred twenty eight
eight hundred thirty
..
..
..
one thousand four hundred thirty six
one thousand four hundred thirty eight
one thousand four hundred forty
one thousand four hundred forty two
one thousand four hundred forty four
one thousand four hundred forty six
one thousand four hundred forty eight
one thousand four hundred fifty
one thousand four hundred fifty two
one thousand four hundred fifty four
one thousand four hundred fifty six
one thousand four hundred fifty eight
one thousand four hundred sixty
one thousand four hundred sixty two
knowledge needed or lessons gain!
1. converting integer to string/char and vice versa.
2. using ARRAY and how to manipulate its item thru for loops.
3. Basic math operations such as % operator and division.
4. Lessons! sometimes it is useful to visualize what is the output! and from that, create or determine any repeated routines whether you will be going to use array of strings or numbers using for loop or if statements to get the distinguished PATTERNS.
5. Learn how to count by reading... yes... im not kidding. after reading the numbers by words instead of digits. You will get some clues....
cheers...
problem solved
Similar Threads |
|