emilia98

Number From 0 To 100 To Text _ 2

May 17th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.11 KB | None | 0 0
  1. //Preslav Mihaylov's solution, completed by me --> TOO LONG, BUT CORRECT
  2. using System;
  3.  
  4. namespace NumbersTo100ToText_2
  5. {
  6.     class NumbersTo100ToText_2
  7.     {
  8.         static void Main()
  9.         {
  10.             string firstWord = "";
  11.             string secondWord = "";
  12.             int number = int.Parse(Console.ReadLine());
  13.  
  14.             bool isValid = true;
  15.             if (number < 0)
  16.             {
  17.                 isValid = false;
  18.             }
  19.  
  20.             int units = number % 10;  //edinici
  21.             number = number / 10;
  22.             int tens = number % 10; //desetici
  23.             number = number / 10;
  24.             int hundreds = number % 10; //stotici
  25.  
  26.             if (hundreds == 0 && isValid)
  27.             {
  28.                 if(units == 0)
  29.                 {
  30.                     secondWord = "";
  31.                 }
  32.                 if (units == 1)
  33.                 {
  34.                     secondWord = "one";
  35.                 }
  36.                 else if (units == 2)
  37.                 {
  38.                     secondWord = "two";
  39.                 }
  40.                 else if (units == 3)
  41.                 {
  42.                     secondWord = "three";
  43.                 }
  44.                 else if (units == 4)
  45.                 {
  46.                     secondWord = "four";
  47.                 }
  48.                 else if (units == 5)
  49.                 {
  50.                     secondWord = "five";
  51.                 }
  52.                 else if (units == 6)
  53.                 {
  54.                     secondWord = "six";
  55.                 }
  56.                 else if (units == 7)
  57.                 {
  58.                     secondWord = "seven";
  59.                 }
  60.                 else if (units == 8)
  61.                 {
  62.                     secondWord = "eight";
  63.                 }
  64.                 else if (units == 9)
  65.                 {
  66.                     secondWord = "nine";
  67.                 }
  68.  
  69.                 if(tens == 0)
  70.                 {
  71.                     if(units==0)
  72.                     {
  73.                         secondWord = "zero";
  74.                     }
  75.                 }
  76.                 else if (tens == 1)
  77.                 {
  78.                     secondWord = "";
  79.                     if (units == 0)
  80.                     {
  81.                         firstWord = "ten";
  82.                     }
  83.                     else if (units == 1)
  84.                     {
  85.                         firstWord = "eleven";
  86.                     }
  87.                     else if (units == 2)
  88.                     {
  89.                         firstWord = "twelve";
  90.                     }
  91.                     else if (units == 3)
  92.                     {
  93.                         firstWord = "thirteen";
  94.                     }
  95.                     else if (units == 4)
  96.                     {
  97.                         firstWord = "fourteen";
  98.                     }
  99.                     else if (units == 5)
  100.                     {
  101.                         firstWord = "fifteen";
  102.                     }
  103.                     else if (units == 6)
  104.                     {
  105.                         firstWord = "sixteen";
  106.                     }
  107.                     else if (units == 7)
  108.                     {
  109.                         firstWord = "seventeen";
  110.                     }
  111.                     else if (units == 8)
  112.                     {
  113.                         firstWord = "eighteen";
  114.                     }
  115.                     else if (units == 9)
  116.                     {
  117.                         firstWord = "nineteen";
  118.                     }
  119.                 }
  120.                 if (tens == 2)
  121.                 {
  122.                     firstWord = "twenty";
  123.                 }
  124.                 else if (tens == 3)
  125.                 {
  126.                     firstWord = "thirty";
  127.                 }
  128.                 else if (tens == 4)
  129.                 {
  130.                     firstWord = "fourty";
  131.                 }
  132.                 else if (tens == 5)
  133.                 {
  134.                     firstWord = "fifty";
  135.                 }
  136.                 else if (tens == 6)
  137.                 {
  138.                     firstWord = "sixty";
  139.                 }
  140.                 else if (tens == 7)
  141.                 {
  142.                     firstWord = "seventy";
  143.                 }
  144.                 else if (tens == 8)
  145.                 {
  146.                     firstWord = "eighty";
  147.                 }
  148.                 else if (tens == 9)
  149.                 {
  150.                     firstWord = "ninety";
  151.                 }
  152.  
  153.                 if(secondWord == "")
  154.                 {
  155.                     Console.WriteLine(firstWord);
  156.                 }
  157.                 else if(firstWord == "")
  158.                 {
  159.                     Console.WriteLine(secondWord);
  160.                 }
  161.                 else
  162.                 {
  163.                     Console.WriteLine("{0} {1}", firstWord, secondWord);
  164.                 }
  165.                
  166.             }
  167.             else if ((hundreds == 1 && (units == 0 && tens == 0)) && isValid)
  168.             {
  169.                 Console.WriteLine("one hundred");
  170.             }
  171.             else
  172.             {
  173.                 Console.WriteLine("invalid number");
  174.             }
  175.            
  176.         }
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment