Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace NumWords
- {
- class Program
- {
- static String NumWords(double n)
- {
- string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
- "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
- string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty",
- "sixty", "seventy", "eighty", "ninty" };
- string[] suffixesArr = new string[] { "thousand" };
- string words = "";
- bool tens = false;
- if (n > 3000)
- {
- Console.WriteLine("o p s tama na sobra na");
- Console.ReadLine();
- Environment.Exit(0);
- }
- if (n == 0) {
- Console.WriteLine("zero");
- Console.ReadLine();
- Environment.Exit(0);
- }
- if (n >= 1000)
- {
- if (n % 1000 > 0) words += NumWords(Math.Floor(n / 1000)) + " thousand, ";
- else words += NumWords(Math.Floor(n / 1000)) + " thousand";
- n %= 1000;
- }
- if (0 <= n && n <= 999)
- {
- if ((int)n / 100 > 0)
- {
- words += NumWords(Math.Floor(n / 100)) + " hundred";
- n %= 100;
- }
- if ((int)n / 10 > 1)
- {
- if (words != "")
- words += " ";
- words += tensArr[(int)n / 10 - 2];
- tens = true;
- n %= 10;
- }
- if (n < 20 && n > 0)
- {
- if (words != "" && tens == false)
- words += " ";
- words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]);
- n -= Math.Floor(n);
- }
- }
- return words;
- }
- static void Main(string[] args)
- {
- Console.Write("input: ");
- Double n = Double.Parse(Console.ReadLine());
- Console.WriteLine("output: " + "{0}", NumWords(n));
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement