Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2.  
  3. namespace JakeNumbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             string input = "936";
  11.             int inputInt = int.Parse(input);
  12.  
  13.             int[] inputDigits = new int[input.Length];
  14.             for (int i = input.Length - 1; i >= 0; i--)
  15.             {
  16.                 //Seprate the digits into an array
  17.                 inputDigits[i] = int.Parse(input.Substring(i, 1));
  18.             }
  19.  
  20.             string[] numberNames = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen" };
  21.             string[] tensNames = { "","teen", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  22.  
  23.             string output = "";
  24.  
  25.             if (inputInt == 0)
  26.             {
  27.                 output = "zero";
  28.             }
  29.             else if (inputInt < 16)
  30.             {
  31.                 output = numberNames[inputInt];
  32.             }
  33.             else if (inputInt < 20)
  34.             {
  35.                 output = numberNames[inputDigits[1]] + tensNames[1];
  36.             } else
  37.             {
  38.                 int i = 0;
  39.  
  40.                 if (input.Length == 3)
  41.                 {
  42.                     output = numberNames[inputDigits[i++]] + " hundred";
  43.  
  44.                     if (inputDigits[i] + inputDigits[i + 1] != 0)
  45.                     {
  46.                         output += " and ";
  47.                     }
  48.  
  49.                 }
  50.  
  51.                 string dash = "-";
  52.                 if (inputDigits[i + 1] == 0 || inputDigits[i] == 0){
  53.                     dash = "";
  54.                 }
  55.                 output += tensNames[inputDigits[i++]] + dash + numberNames[inputDigits[i]];
  56.  
  57.             }
  58.  
  59.             Console.WriteLine(output);
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement