Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: need C# advice

  1. #11

    Quote Originally Posted by bishop__ View Post
    para ma shorten ang program bai, then dynamic ang number of digits ma support, maayo gyud mag gamit ug % bai.
    actually na ka gamit naman ko modulo technique bai pero kalimut nako unsa 2...pero ok ra sa ni bai oi kay 1st la na ko time 2nd sakit na kaayo ko ulo 3rd mahurot na ako dugo sige nosebleed...hehehehe..
    but after i pass this ill probably do it for fun sake...samot pa gyud to ka taas

  2. #12
    ok this is the revise edition i made from sir bluedes considering 11 to 19

    int tempnum;
    string numstring="";
    string num= "";
    string [] ones= new string[]
    {"one", "two", "three", "four","five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" ,"thirteen",
    "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
    }
    string [] tens= new string[]
    {
    ten,twenty,thirty,fourty,fifty,sixty,seventy,eight y,ninety
    }

    Console.Write("Enter num: ");
    num= console.readline();

    if (num.length == 3)
    {
    tempnum = (int) num[0];
    numstring= ones[tempnum-1] + " " + "hundred" + " ";
    tempnum = (int) num[1];
    if (tempnum!=0&& tempnum!=1)
    {
    numstring + = tens[tempnum-1] + " ";
    tempnum=(int) num[2];
    if(tempnum!=0)
    {
    numstring +=ones[tempnum-1]

    }

    }
    else if (tempnum!=0)
    {
    tempnum=((int)num[1])+((int)num[2]);
    numstring + = ones[tempnum-1]
    }
    }
    else if (num.length == 2)
    {
    tempnum = (int) num[0];
    if (tempnum!=0&& tempnum!=1)
    {
    numstring + = tens[tempnum-1] + " ";
    tempnum=(int) num[1];
    if(tempnum!=0)
    {
    numstring +=ones[tempnum-1]

    }

    }
    else if (tempnum!=0)
    {
    tempnum=((int)num[1])+((int)num[2]);
    numstring + = ones[tempnum-1]
    }
    }
    else if (num.length==1)
    {
    tempnum = (int) num[0];
    if (tempnum != 0)
    {
    numstring = ones[tempnum - 1];
    }

    matulog sa ko kad**** kay labad na ako ulo

  3. #13
    string [] tens= new string[]
    {
    ten,twenty,thirty,fourty,fifty,sixty,seventy,eight y,ninety
    }
    wlay double qoute
    hehehe

  4. #14
    Quote Originally Posted by moz_k2 View Post
    wlay double qoute
    hehehe
    yeah kita ko ana pero im to tired to care...hehehe..tnx for pointing it out

  5. #15
    Quote Originally Posted by Deathnote View Post
    yup 3 digits ra bai...nindota ana imo sir kolz oi...libog pa lang for me kay dont know what indexof() method is and some of the other codes...but studyuan nako na unya

    sir bluedes sakto bitaw na imo..damn nag lisod lisod man ko for loop...reallly need to learn alot pa

    question lang sir...is "(int)num[0]" similar to "int.parse(num[0])"?

    yeah.. murag parehas ra na.. tan-awa lng sa documentation sa C# about Type Casting..
    learn to use that often, kay maka-improve na sa imong speed and efficiency, and walay libog kung debugging..

  6. #16
    Quote Originally Posted by bluedes View Post
    yeah.. murag parehas ra na.. tan-awa lng sa documentation sa C# about Type Casting..
    learn to use that often, kay maka-improve na sa imong speed and efficiency, and walay libog kung debugging..
    yup search na nako and its the same...learn something new na sad...txn sir bluedes

  7. #17
    Ok this one is an abbreviation of my last post, much shorter, but can only take 3 digits. You don't even need a loop. And you absolutely don't need a hash, you'll need it if you construct a dictionary, but your key
    here is an ordered int, so you won't need it.

    You will only need the loop if you exceed more than 3 digits (our translation base is only 3 digits long), if you exceed more than this, you would need a tracker for the thousandths, millions, etc (see my first post):
    [3 digits] million [3 digits] thousand [3 digits]

    and the 3 digits can be broken down to:
    x (hundred) -> y z (if less than twenty, belongs to the ones set) or y (tens) -> z (ones)

    Code:
    public static string IntegerToWords(long inputNum)
    {
          int dig1, dig2, dig3, lasttwo, threeDigits;
    
          string retval = "";
          string x = "";
          string[] ones = {"zero","one","two","three","four","five","six","seven",
    "eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen", 
    "nineteen"};
          string[] tens = {"zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety" };
    
          if (inputNum == 0)
              return ("zero");
    
          string s = inputNum.ToString();
    
          // Sanity check ... s length should not be greater than 3 digits
          if (s.Length > 3) return "";
    
          // Separate the three digits
          threeDigits = int.Parse(s);
          lasttwo = threeDigits%100; // the last 2 digits, is the remainder of 100
          dig1 = threeDigits/100; // The hundreths
          dig2 = lasttwo/10;      // The tens
          dig3 = (threeDigits%10);    // The ones position
    
          // check that the last two digits is not a zero
          if (lasttwo > 0)
          {
              if (lasttwo < 20) // if less than 20, use "ones" only
                  retval = ones[lasttwo] + " " + retval;
              else // otherwise, use both "tens" and "ones" array
                  retval = tens[dig2] + " " + ones[dig3] + " " + retval;
          }
    
          // if a hundreds part is there, translate it
          if (dig1 > 0)
                retval = ones[dig1] + " hundred " + retval;
    
          return (retval);
    }
    Last edited by kolz; 07-02-2009 at 11:07 AM.

  8. #18
    ahhhh sayop man diay num[0]...dili man diay makuha ang char sa index...hehehe....pag type nako 9, 57 ang tempnum....hehehehe..gamit diay substring..pero nangita na sad negative si maam..really hate it when mo hatag ug instructions after na nahimo ang code..hehehehe

    sir kolz tnx for the code..studyuan nako na run


    sir kolz

    pwede mo ask? what does this statement mean?

    x = (s.Length < 3) ? s : s.Substring(s.Length - 3, 3);
    if it is greater than 3 the value of x would be s.Substring(s.Length - 3, 3);?
    and if it is false value would be s?

    how about this?

    while (retval.IndexOf(" ") > 0)
    retval = retval.Replace(" ", " ");

    retval = retval.Trim();

    i dont get this code at all....tan tangon ang spaces? mag tupad na siya bai...tnx and sry kung na ka disturbo

  9. #19
    x = (s.Length < 3) ? s : s.Substring(s.Length - 3, 3);

    This is to get the last three digits of the number for each loop:

    for example the number is s = "123456789"
    s.Length = 9
    s.Length-3 = 6
    s.Substring(s.Length-3, 3) = returns the string starting from (s.Length-3), up to 3 characters
    s.Substring(s.Length-3, 3) = "789" for the example above

    Code:
    x = (s.Length < 3) ? s : s.Substring(s.Length - 3, 3) means
    if (s.Length < 3)
        x = s;
    else
        x = s.Substring(s.Length -3, 3)
    So for the first loop you process "789" in the second loop, s will become:
    s = (s.Length - 3) > 0 ? s.Substring(0, s.Length - 3) : "";

    which means (trim the last 3 digits):
    Code:
    if ((s.Length - 3) > 0)
       s = s.Substring(0, s.Length -3); // if s = "123456789", s now becomes "123456", remove the last three.
    else
       s = ""; // Processed the last 3 digits already

  10. #20
    Quote Originally Posted by Deathnote View Post
    how about this?

    while (retval.IndexOf(" ") > 0)
    retval = retval.Replace(" ", " ");

    retval = retval.Trim();

    i dont get this code at all....tan tangon ang spaces? mag tupad na siya bai...tnx and sry kung na ka disturbo
    if you examine the source ... its:

    while (retval.IndeOf("_ _" > 0) // kung kakita ta ug double ang spaces sa retVal
    retval = retval.Replace("_ _", "_"); // ilisdan ang double space with single space lang.

    kanang first notice double spaces na siya, it just means if there are double spaces in the return value replace it with a single space, aron nindot tan-awn ang result.


    kanang retval.Trim(), just remove the trailing spaces in the string.

  11.    Advertisement

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

 
  1. Need your advice for a wireless router
    By jhnpl in forum Computer Hardware
    Replies: 20
    Last Post: 08-09-2012, 09:40 PM
  2. Why do we have to experience pain? NEED YOUR ADVICE
    By IamTheWind- in forum "Love is..."
    Replies: 88
    Last Post: 04-04-2012, 11:03 PM
  3. Hard Disk Probs..need an advice of what to do..
    By benz_jie2002 in forum Computer Hardware
    Replies: 17
    Last Post: 01-23-2007, 10:24 PM
  4. dvd r/w : unsa-on pag burn ug dvd's : need ur advice
    By rasta_dubbed in forum Computer Hardware
    Replies: 14
    Last Post: 12-09-2005, 06:31 PM
  5. need your advice on lcd monitors...
    By for_real in forum Computer Hardware
    Replies: 9
    Last Post: 09-12-2005, 02:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top