Please Help A Noob Here (plz Im Begging You)

This is a discussion on Please Help A Noob Here (plz Im Begging You) within the C Programming forums, part of the General Programming Boards category; hi guys im back i just realised for the coverting years into words bit like eg: 2008 ----> twenty hundred ...

  1. #61
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    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. #62
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Something like
    2008 / 1000
    2008 / 100 & 0x9
    2008 / 10 0x9
    2008 & 0x9
    Might work for getting each decimal
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #63
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Elysia View Post
    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. #64
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Bah, it was worth a try.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #65
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #66
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    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. #67
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    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. #68
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    An example of what, exactly?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #69
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    a sample of the code....
    i got this so far
    Code:
        if (year/1000)=4
            printf("forty")
            if ((year%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. #70
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #71
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    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. #72
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #73
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #74
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    i got the following but i do not know why it doesn't work
    Code:
    {
            if ((year/1000)=4)
            {
            printf("forty");
            }
            if (((year%1000)/10)=3)
            {
            printf("three hundrend");
            }
            if (((year%100)%100)=2)
            {
            printf("twenty");
            }
            if ((year%10)=1)
            {
            printf("one\n");
            }
    }

  15. #75
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by bobbie18 View Post
    i got the following but i do not know why it doesn't work
    Code:
    {
            if ((year/1000)==4)
            {
            printf("forty");
            }
            if (((year%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.

Page 5 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. The ultimate noob lol...plz help
    By thatpkrguy in forum C++ Programming
    Replies: 14
    Last Post: 11-10-2005, 05:53 PM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 02:04 PM
  4. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21