Thread: Please Help A Noob Here (plz Im Begging You)

  1. #76
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    i c i c thx for the reply
    can you give me some ideas of how to write the year 1782 for eg?
    cause wont i have to create a eleven to nineteen dictionary for the program?
    any samples?

  2. #77
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    and i dont know why the output is
    fortythree hundrendone
    i cant get the twenty out for some reasons???

  3. #78
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bobbie18 View Post
    i c i c thx for the reply
    can you give me some ideas of how to write the year 1782 for eg?
    cause wont i have to create a eleven to nineteen dictionary for the program?
    any samples?
    You'll need every word you'll want to print. Seventeen, sixty, eight, forty, etc. The idea hasn't changed since you got it right two posts ago. Divide.

  4. #79
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    but let say 1782
    how does the divison work on that?
    1782/1000 and then ???
    lol im so confused
    PLEASE do you mind giving me an example
    PLEASE literally begging you

  5. #80
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by bobbie18 View Post
    but let say 1782
    how does the divison work on that?
    1782/1000 and then ???
    lol im so confused
    PLEASE do you mind giving me an example
    PLEASE literally begging you
    Missed one: that should be a divide by 10 in the twenty, not a divide by 100.

    I don't know what else to say except you've already posted the example. But just because:
    Code:
    int number = 4321;
    int thousands = number/1000;
    int hundreds = (number%1000)/100;
    int tens = (number%100)/10;
    int ones = number%10;
    
    if (thousands == 1)
        printf("One");
    else if (thousands == 2)
        printf("Two");
    else if (thousands == 3)
        printf("Three");
    else if (thousands == 4)
        printf("Four");
    else if (thousands == 5)
        printf("Five");
    else if (thousands == 6)
        printf("Six");
    else if (thousands == 7)
        printf("Seven");
    else if (thousands == 8)
        printf("Eight");
    else if (thousands == 9)
        printf("Nine");
    if (thousands)
        printf(" thousand ");
    et cetera.

  6. #81
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    but they want it in this format:
    Enter year and month: 1980 2
    nineteen hundred eighty
    has three hundred and sixty six (366) days
    February has 29 days
    % ./assn1
    Enter year and month: 1980 3
    nineteen hundred eighty
    has three hundred and sixty six (366) days
    March has 31 days
    % ./assn1
    Enter year and month: 2000 2
    twenty hundred
    has three hundred and sixty six (366) days
    February has 29 days

  7. #82
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So if you had read the example that would be a long, but trivial, change.

  8. #83
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    so let say 1782
    wouldn't it be
    seventeen hundred eighty two
    but then i cant seperate 17 from the 1782 with the normal method....

  9. #84
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That implies that you should break it up into: hundreds, tens, ones.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #85
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    but i break it into hundreds it might be convienet for years from 1700-1900
    but let say 8999 it will be hard doing hundreds

  11. #86
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    but let say 8999 it will be hard doing hundreds
    It is as hard as doing 89.

    There are two possible solutions that come to mind. One involves a massive bunch of if-else statements to handle the numbers from 0 to 99 inclusive. This would be used first for the century, and then for the decade and individual year. The other solution is to check if the first number is a 1. If it is, then you use "ten", "eleven" etc. If not, you just use "twenty", "thirty" etc.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #87
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx for the reply
    can u show me an if statement for the yr 1782 for eg
    which would convert to seventeen hundred and eighty two?

  13. #88
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    I am not sure whether you are supposed to use character arrays for your assignment, but nevertheless, all you need is

    Code:
    const char *unitStr[10] = {     // string constants for unit places
            "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"
        };
    
        const char *teenStr[10] = {     // string constants for teen numbers
            "Ten",
            "Eleven",
            "Twelve",
            "Thirteen",
            "Fourteen",
            "Fifteen",
            "Sixteen",
            "Seventeen",
            "Eighteen",
            "Nineteen",
        };
    
        const char *tenStr[10] = {      // string constants for tens places
            "Zero",
            "Ten",
            "Twenty",
            "Thirty",
            "Forty",
            "Fifty",
            "Sixty",
            "Seventy",
            "Eighty",
            "Ninety",
        };
    then, get the hundreds, tens and ones part of the year
    Code:
    hundreds = number/100;
    tens = (number % 100)/10;
    ones = (number %100)%10;
    From this point onwards, you need a bunch of if statements to see if the variable hundreds is single digit, b/w 11 and 19 (inclusive) or greater than 19 to get the appropriate output string :-). The same logic goes with tens and ones.

    I am tempted to post my code but its against homework rule

    cheers
    maverix

  14. #89
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx for the reply
    ...apparently we can only use a lot of if statements so i think we aren't allow to use character array
    so so far im stuck on how to do a year like 1782 using only IF and IF else statemtns
    any examples will be GREATLY appreicated... im wasting far 2 much time on this

  15. #90
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    Quote Originally Posted by bobbie18 View Post
    so so far im stuck on how to do a year like 1782 using only IF and IF else statemtns
    any examples will be GREATLY appreicated... im wasting far 2 much time on this
    break the year 1782 into hundreds, tens and ones (as shown in my previous post)
    Code:
    break the year 1782 into hundreds, tens and ones (as shown in my previous post)
    if(hundreds == 17)
    	printf("Seventeen Hundred");
    	
    if(tens == 8)
    	printf(" and Eighty");
    	
    if(ones == 2)
    	printf(" Two");
    but this is only for 1782
    you would be doomed if you follow this approach coz you have to deal with a lot many years

    good luck
    maverix

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, 06:53 PM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 03: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