Let Share Codes

A Member? Please Login  
type your username and password to login
Date: July 24, 2008, 09:39 AM
223054 members and 126493 Topics
Latest Member: gloriousif
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Let Share Codes
Pages: (1) (2) Go Down Send this topic Notify of replies
Author Topic: Let Share Codes  (Read 1113 views)
krazied (m)
Re: Let Share Codes
« #32 on: November 06, 2007, 04:32 PM »

hey guys am a student just studied c and trying to practice but can't seem to make my compiler work is there anywhere to get a c compiler better still java's and how do you use d java runtime enviroment just downloaded one please try being explicit   Cry
SayoMarvel (m)
Re: Let Share Codes
« #33 on: November 11, 2007, 05:45 PM »

I don't know if anyone needs the source code of my simple application that calculates the determinant of a 3 by 3 square maltrix.
Smart K. (m)
Re: Let Share Codes
« #34 on: November 12, 2007, 01:01 PM »

Quote
I don't know if anyone needs the source code of my simple application that calculates the determinant of a 3 by 3 square maltrix.

You have tried man. Keep it up. I did exactly that, about 8 years ago when learning C. You can push it a little 4ward by use it to solve 3X3 simultaneous eqns. I mean real life situations like determining prices of known items.

Good luck.
Smart K. (m)
Re: Let Share Codes
« #35 on: November 12, 2007, 05:26 PM »

Here is the code that converts amount in double to amount in words. I did it in C#. You may copy and use it if u like. It uses Nigeria currency :

Usage: AmountInWord(115.50) returns one hundred and fifteen naira fifty kobo only.

public static string AmountInWord(string amount)
        {
            long num;
            long num2;
            string str2;
            string str3;
            string str = "";
            string[] strArray = new string[5];
            amount = amount.Replace(",", "");
            amount = amount.Replace(" ", "");
            str = "";
            try
            {
                double num3 = double.Parse(amount);
            }
            catch
            {
                throw new Exception("The amount supplied is not a number and therefore not convertuble");
            }
            strArray[0] = "Trillion ";
            strArray[1] = "Billion ";
            strArray[2] = "Million ";
            strArray[3] = "Thousand ";
            strArray[4] = " ";
            int index = amount.IndexOf(".");
            if (index > -1)
            {
                str2 = amount.Substring(0, index);
                str3 = amount.Substring(index, amount.Length - index);
                if (str2.Length > 15)
                {
                    throw new Exception("The amount supplied must not be greater than 999 999 999 999 999.99");
                }
                str2 = string.Format("{0:D15}", long.Parse(str2));
                str3 = string.Format("{0:F2}", double.Parse(str3));
            }
            else
            {
                if (amount.Length > 15)
                {
                    throw new Exception("The amount supplied must not be greater than 999 999 999 999 999.99");
                }
                str2 = string.Format("{0:D15}", long.Parse(amount));
                str3 = "0.00";
            }
            amount = str2 + str3.Substring(1, 3);
            int num5 = 0;
            for (int i = 0; num5 <= 4; i += 3)
            {
                if (long.Parse(amount.Substring(i, 3)) > 0)
                {
                    if (long.Parse(amount.Substring(i, 1)) > 0)
                    {
                        num = long.Parse(amount.Substring(i + 1, 1));
                        num2 = long.Parse(amount.Substring(i + 2, 1));
                        if ((num > 0) || (num2 > 0))
                        {
                            str = str + convert(amount.Substring(i, 1)) + "Hundred And ";
                        }
                        else
                        {
                            str = str + convert(amount.Substring(i, 1)) + "Hundred ";
                        }
                    }
                    num = long.Parse(amount.Substring(i + 1, 2));
                    num2 = long.Parse(amount.Substring(i + 1, 2));
                    if ((num >= 20) && (num2 <= 0x63))
                    {
                        num = long.Parse(amount.Substring(i + 1, 1) + "0");
                        num2 = long.Parse(amount.Substring((i + 1) + 1, 1));
                        str = str + convert(num) + convert(num2);
                    }
                    num = long.Parse(amount.Substring(i + 1, 2));
                    num2 = long.Parse(amount.Substring(i + 1, 2));
                    if ((num >= 1) && (num2 < 20))
                    {
                        str = str + convert(amount.Substring(i + 1, 2));
                    }
                    str = str + strArray[num5];
                }
                num5++;
            }
            if (long.Parse(amount.Substring(0, 15)) > 0)
            {
                str = str + "naira ";
            }
            num = int.Parse(amount.Substring(amount.Length - 2, 2));
            if (num > 0)
            {
                num = long.Parse(amount.Substring(amount.Length - 2, 2));
                num2 = long.Parse(amount.Substring(amount.Length - 2, 2));
                if ((num >= 20) && (num2 <= 0x63))
                {
                    num = long.Parse(amount.Substring(0x10, 1) + "0");
                    num2 = long.Parse(amount.Substring(0x11, 1));
                    str = str + convert(num) + convert(num2);
                }
                num = long.Parse(amount.Substring(amount.Length - 2, 2));
                if ((num >= 1) && (num < 20))
                {
                    str = str + convert(amount.Substring(amount.Length - 2, 2));
                }
                str = str + "kobo ";
            }
            return (str + "only").ToLower();
        }

        private static string convert(long amount)
        {
            return convert(amount.ToString());
        }

        private static string convert(string amount)
        {
            switch (int.Parse(amount))
            {
                case 70:
                    return "seventy ";

                case 80:
                    return "eighty ";

                case 90:
                    return "ninety ";

                case 0:
                    return "";

                case 1:
                    return "one ";

                case 2:
                    return "two ";

                case 3:
                    return "three ";

                case 4:
                    return "four ";

                case 5:
                    return "five ";

                case 6:
                    return "six ";

                case 7:
                    return "seven ";

                case 8:
                    return "eight ";

                case 9:
                    return "nine ";

                case 10:
                    return "ten ";

                case 11:
                    return "eleven ";

                case 12:
                    return "twelve ";

                case 13:
                    return "thirteen ";

                case 14:
                    return "fouteen ";

                case 15:
                    return "fifteen ";

                case 0x10:
                    return "sixteen ";

                case 0x11:
                    return "seventeen ";

                case 0x12:
                    return "eighteen ";

                case 0x13:
                    return "nineteen ";

                case 20:
                    return "twenty ";

                case 30:
                    return "thirty ";

                case 40:
                    return "fourty ";

                case 50:
                    return "fifty ";

                case 60:
                    return "sixty ";
            }
            return "";
        }

        public static bool IsNumeric(string val)
        {
            try
            {
                double num = double.Parse(val);
                return true;
            }
            catch
            {
                return false;
            }
        }

Good luck
yinka007 (m)
Re: Let Share Codes
« #36 on: November 15, 2007, 11:43 AM »

i think it will be better to share codes as attachments or using URL's eg. http://www.spiralteck.com
Smart K. (m)
Re: Let Share Codes
« #37 on: May 12, 2008, 11:32 AM »

Long time! Cooking up something ,  Sorry, I was away for a long time.
 Please Need Help With Writing These C++ Programmes Please This Is Really Urgent  Qbasic On Windows Xp  Why Nigerian Software Firms Are Absent On The Global Map  Page 2
Pages: (1) (2) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.