Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class NumberAsWords
- {
- static void Main()
- {
- Console.WriteLine("Enter integer number in range 0-999");
- try
- {
- int inputNumber = int.Parse(Console.ReadLine());
- string[] sBasicNumbers = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
- int[] iBasicNumbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- string[] sFrom10To19 = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
- int[] iFrom10To19 = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
- string[] sRoundedDecimals = {"Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
- int[] iRoundedDecimals = {20, 30, 40, 50, 60, 70, 80, 90};
- if (inputNumber >= 0 && inputNumber <= 99)
- {
- if (inputNumber >= 0 && inputNumber <= 9)
- {
- for (int numberVaule = iBasicNumbers[0]; numberVaule <= iBasicNumbers[9]; numberVaule++ )
- {
- if(inputNumber == numberVaule)
- {
- Console.WriteLine(sBasicNumbers[numberVaule]);
- }
- }
- }
- if(inputNumber >= 10 && inputNumber <= 19)
- {
- for (int numberValue = iFrom10To19[0]; numberValue <= iFrom10To19[9]; numberValue++)
- {
- if (inputNumber == numberValue)
- {
- Console.WriteLine(sFrom10To19[numberValue-10]);
- }
- }
- }
- if (inputNumber >= 20 && inputNumber <= 99)
- {
- int firstDigit = inputNumber / 10;
- int secondDigit = inputNumber % 10;
- if (secondDigit == 0)
- {
- for (int numberValue = iRoundedDecimals[0]; numberValue <= iRoundedDecimals[7]; numberValue+=10)
- {
- if(inputNumber == numberValue)
- {
- int numberPosition = (numberValue - 20) / 10;
- Console.WriteLine(sRoundedDecimals[numberPosition]);
- }
- }
- }
- if( secondDigit != 0)
- {
- for (int numberValue = iBasicNumbers[0]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (secondDigit == numberValue)
- {
- string twoDigit = sBasicNumbers[secondDigit];
- for (int numberValue1 = iBasicNumbers[0]; numberValue1 <= iBasicNumbers[9]; numberValue1++)
- {
- if (numberValue1 == firstDigit)
- {
- string oneDigit = sRoundedDecimals[firstDigit - 2];
- Console.WriteLine("{0} {1}", oneDigit, twoDigit);
- }
- }
- }
- }
- }
- }
- }
- if(inputNumber >= 100 && inputNumber <= 999)
- {
- int firstDigit = (inputNumber / 100) % 10;
- int secondDigit = (inputNumber / 10) % 10;
- int thirdDigit = inputNumber % 10;
- if(secondDigit == 0 && thirdDigit ==0)
- {
- for (int numberValue = iBasicNumbers[1]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (firstDigit == numberValue)
- {
- string fDigit = sBasicNumbers[firstDigit] + " Hundred";
- Console.WriteLine(fDigit);
- }
- }
- }
- if( secondDigit == 0)
- {
- for (int numberValue = iBasicNumbers[1]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (firstDigit == numberValue)
- {
- string fDigit = sBasicNumbers[firstDigit] + " Hundred";
- for (int numberValue1 = iBasicNumbers[1]; numberValue1 <= iBasicNumbers[9]; numberValue1++)
- {
- if (thirdDigit == numberValue1)
- {
- string lastDigit = sBasicNumbers[thirdDigit];
- Console.WriteLine("{0} and {1}",fDigit ,lastDigit);
- }
- }
- }
- }
- }
- if(secondDigit == 1)
- {
- for (int numberValue = iBasicNumbers[1]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (firstDigit == numberValue)
- {
- string fDigit = sBasicNumbers[firstDigit] + " Hundred";
- for (int numberValue2 = iFrom10To19[0]; numberValue2 <= iFrom10To19[9]; numberValue2++)
- {
- int findFirstNum = inputNumber / 100;
- int useFirstNum = findFirstNum * 100;
- int removeHundreds = inputNumber - useFirstNum;
- if (removeHundreds == numberValue2)
- {
- string lastTwoDigitsTo19 = sFrom10To19[removeHundreds-10];
- Console.WriteLine("{0} and {1}", fDigit, lastTwoDigitsTo19);
- }
- }
- }
- }
- }
- if (thirdDigit == 0)
- {
- for (int numberValue = iBasicNumbers[1]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (firstDigit == numberValue)
- {
- string fDigit = sBasicNumbers[firstDigit] + " Hundred";
- for (int numberValue2 = iRoundedDecimals[0]; numberValue2 <= iRoundedDecimals[7]; numberValue2 += 10)
- {
- int findFirstNum = inputNumber / 100;
- int useFirstNum = findFirstNum * 100;
- int removeHundreds = inputNumber - useFirstNum;
- if (numberValue2 == removeHundreds)
- {
- int numberPosition = (numberValue2 - 20) / 10;
- string thirdDigitIs0 = sRoundedDecimals[numberPosition];
- Console.WriteLine("{0} and {1}", fDigit, thirdDigitIs0);
- }
- }
- }
- }
- }
- if ((secondDigit != 0 && thirdDigit != 0) && secondDigit != 1)
- {
- for (int numberValue = iBasicNumbers[1]; numberValue <= iBasicNumbers[9]; numberValue++)
- {
- if (firstDigit == numberValue)
- {
- string fDigit = sBasicNumbers[firstDigit] + " Hundred";
- for (int numberValue2 = iBasicNumbers[1]; numberValue2 <= iBasicNumbers[9]; numberValue2++)
- {
- if (secondDigit == numberValue2)
- {
- string sDigit = sRoundedDecimals[secondDigit - 2];
- for (int numberValue3 = iBasicNumbers[1]; numberValue3 <= iBasicNumbers[9]; numberValue3++)
- {
- if (thirdDigit == numberValue3)
- {
- string tDigit = sBasicNumbers[thirdDigit];
- Console.WriteLine("{0} and {1} {2}", fDigit, sDigit, tDigit);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- catch
- {
- Console.WriteLine("Invalid input number, try again and be careful!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement