1. hi guys im back
i just realised for the coverting years into words bit like eg:
2008 ----> twenty hundred and eight
How do i do it if i am only allowed using the if method?
so far i got
year divide by 1000 and then using the remainder but i sort of lost myself on that... any more suggestions?

2. Something like
2008 / 1000
2008 / 100 & 0x9
2008 / 10 0x9
2008 & 0x9
Might work for getting each decimal

3. Originally Posted by Elysia
Something like
2008 / 1000
2008 / 100 & 0x9
2008 / 10 0x9
2008 & 0x9
Might work for getting each decimal
And'ing with 0x9 won't work since that will only peel off 1 and 8. Use remainder from the previous division instead.

4. Bah, it was worth a try.

5. If you want "twenty hundred and eight", then you probably want to divide by 100, rather than by 1000 - if you want "two thousand and eight", you should divide by 1000.

--
Mats

6. can someone please demonstrate a code of how to do it for years 4321 for eg. and also i have ABSOLUTE no idea on how to do years such 1700 to 1999. can someone show me a code. Im not getting u guys to do my work but im really lost on how to do this one

7. my teacher forced us to make a program from the stuff we learn such as if statements. so i think i have to create at least 49 if statements but can someone plz show me an example plesase. BEgging you i got so much other work i got to catch up with and this program is burning my time away

8. An example of what, exactly?

--
Mats

9. a sample of the code....
i got this so far
Code:
```    if (year/1000)=4
printf("forty")
if ((year&#37;1000)/10)=3
printf("three hundrend")
if ((year%1000)/100)=2
printf("twenty")
if ((((year%1000)/100)```
but i dont know how to finish it or do years such as 1822 for eg

10. Sample:
Code:
```	int year = 2008;
char buf[5];
char buf2[100] = {0};
sprintf_s(buf, sizeof(buf), "%i", year);
char thousand = buf[0];
char hundred = buf[1];
char tenth = buf[2];
char oneth = buf[3];
if (thousand == '2') strcat_s(buf2, sizeof(buf2), "Two thousand");
strcat_s(buf2, sizeof(buf2), " and ");
//if (buf[1]
if (oneth == '8') strcat_s(buf2, sizeof(buf2), "eight");
puts(buf2);```
If the compiler doesn't accept strcat_s and sprintf_s, then just use strcat and sprintf.

11. elysia thx for ur reply...but i think this too compilcated. we are only allowed to use if and else if statements... is there any chance u can make this simpler?

12. It's as simple as it will be unless you involve a lot of math.
It just converts it to a string and takes the first number, the second, third and fourth.
So the 2, 0, 0, and 8, and translates them into a word using ifs.

13. First of wall, you need to decide if you want twenty-hundred or two-thousand.

If you can't use anything beyond if-statements [which is pretty limiting for this sort of excercise], then it would help to be able to use a function - but you probably aren't allowed that either.

So, divide the number into portions FIRST, like "hundreds = year / 100", "thousands = year / 1000", "tens = (number / 10) % 100", "ones = number % 10". Then you need a big-if-tree where you split decide which number to print based on the thousands, hundreds, etc, etc.

If you can use functions, you can simplify it by making a function that prints "zero" to "ninetynine", and then call that to print thousands, hundreds, and "the rest".

And you can of course use arrays if that's allowed, like in my example I posted yesterday.

--
Mats

14. i got the following but i do not know why it doesn't work
Code:
```{
if ((year/1000)=4)
{
printf("forty");
}
if (((year&#37;1000)/10)=3)
{
printf("three hundrend");
}
if (((year%100)%100)=2)
{
printf("twenty");
}
if ((year%10)=1)
{
printf("one\n");
}
}```

15. Originally Posted by bobbie18
i got the following but i do not know why it doesn't work
Code:
```{
if ((year/1000)==4)
{
printf("forty");
}
if (((year&#37;1000)/100)==3)
{
printf("three hundrend");
}
if (((year%100)/100)==2)
{
printf("twenty");
}
if ((year%10)==1)
{
printf("one\n");
}
}```
And of course, that only works for the year 4321.