Created
January 17, 2017 15:21
-
-
Save Nikola-Andreev/1cc5f1556862e14b39e6fbe38e6a39d2 to your computer and use it in GitHub Desktop.
Number to 100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace numsTo100inText | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int num = int.Parse(Console.ReadLine()); | |
string[] tonineteen = { "zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; | |
string[] toninety = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" }; | |
if (num < 0 ) | |
{ | |
Console.WriteLine("Invalid number"); | |
} | |
else if (num > 100) | |
{ | |
Console.WriteLine("Invalid number"); | |
} | |
else if (num>=0 && num <= 19) | |
{ | |
Console.WriteLine(tonineteen[num]); | |
} | |
else if (num>=20 && num < 100) | |
{ | |
if (num%10 == 0) | |
{ | |
Console.WriteLine(toninety[(num / 10) - 2]); | |
} | |
else | |
{ | |
Console.WriteLine(toninety[(num / 10) - 2] +" "+ tonineteen[(num % 10)]); | |
} | |
} | |
else if (num == 100) | |
{ | |
Console.WriteLine("one hundred"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment