Beispiel #1
0
        static void Main(string[] args)
        {
Start:
            //  string isaac = Console.ReadLine();

            //  Console.WriteLine(isaac.Length);


            //number to convert to text
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.Speak("Enter an input");

            //do
            //{

            //} while (b);

            Console.WriteLine("PLEASE ENTER A NUMBER THAT THE COMPUTER WILL CONVERT TO A STRING AUTOMATICALLY");

            Console.WriteLine("The maximum number you can enter is 1 billion");
            string input = Console.ReadLine();

            //string input = ("78");



            //test to check the length of the input
            if (input.Length == 1)
            {
                string result = Units.Unit(input[0]);
                Console.WriteLine("You entered {0}", result);
                synth.Speak(result);
            }

            else if (input.Length == 2)
            {
                string result = Tens.Ten(input);
                Console.WriteLine("You entered {0}", result);
                synth.Speak(result);
            }

            else if (input.Length == 3)
            {
                string result = Hundreds.Hundred(input);
                Console.WriteLine("You entered {0}", result);
                synth.Speak(result);
            }

            else if (input.Length >= 4 && input.Length <= 6)
            {
                string result = Thousands.Thousand(input);
                Console.WriteLine("You entered {0}", result);
                //synth.Speak(result);
            }

            else if (input.Length >= 7 && input.Length <= 9)
            {
                string result = Million.Millions(input);
                Console.WriteLine("You entered {0}", result);
                //synth.Speak(result);
            }

            else if (input == "10000000000")
            {
                Console.WriteLine("You entered 1 billion ");
            }
            else
            {
                Console.WriteLine("the number is above the expected range, The max number is 1billion");
            }

            goto Start;


            //else if (input.Length == 5)
            //{
            //    string result = TenThousand.TenThousands(input);
            //    Console.WriteLine("You entered {0}", result);
            //    //synth.Speak(result);
            //}
        }
        public static string Hundred(string hundred)
        {
            var tens = hundred.Substring(1);

            string tenth = String.Empty;
            string and;

            if (tens != "00")
            {
                and = " and ";
            }
            else
            {
                and = String.Empty;
            }

            /*This checks if the tens unit in the hundred is zero or not, if it is it simple takes the last
             * digit and pass it to the unit method in the units class, else it calls the tens class with the last two digit(tens part)*/
            if (tens[0] != '0')
            {
                //if tens != '00'
                tenth = Tens.Ten(tens);
            }
            else
            {
                /* this would always run when the first number in the hundred is zero and also
                 * when the last number is not zero(anything else but zero)*/
                if (hundred[0] == '0' || tens[1] != '0')
                {
                    tenth = Units.Unit(tens[1]);
                }
            }



            var x = hundred[0];


            switch (x)
            {
            case '1':

                return("One Hundred" + and + tenth);

                break;

            case '2':

                return("Two Hundred" + and + tenth);

                break;

            case '3':

                return("Three Hundred" + and + tenth);

                break;

            case '4':

                return("Four Hundred" + and + tenth);

                break;

            case '5':

                return("five Hundred" + and + tenth);

                break;

            case '6':

                return("Six Hundred" + and + tenth);

                break;

            case '7':

                return("Seven Hundred" + and + tenth);

                break;

            case '8':

                return("Eight Hundred" + and + tenth);

                break;

            case '9':

                return("Nine Hundred" + and + tenth);

                break;

            case '0':

                return(tenth);

                break;

            default:
                Console.WriteLine("You entered an invalid input");
                return("Invalid");

                break;
            }
            return("");
        }