Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static Dictionary<string,double> conv = new Dictionary<string, double>() { { "mm", 1000 }, { "cm", 100 }, { "miles", 0.000621371192 }, { "inches", 39.3700767 }, { "feet", 3.2808399 }, { "yards", 1.0936133 } };
- static string ConvertLength(string message)
- {
- var arr = message.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- if (arr.Length < 3)
- return "Not enough arguments.";
- var notFound = string.Join("\" and \"", arr.Skip(1).Where(w => !conv.ContainsKey(w)));
- if (!double.TryParse(arr[0], out double val))
- return $"The first argument \"{arr[0]}\" is not a number.";
- else if (notFound.Length != 0)
- return $"I don't understand \"{notFound}\".";
- else
- return $"{val} {arr[1]} is {((val / conv[arr[1]]) * conv[arr[2]]).ToString("N0")} {arr[2]}";
- }
- static void Main(string[] args)
- {
- Console.WriteLine("The options are:\n[{0}].", string.Join(", ", (conv.Select(kvp => kvp.Key))));
- while (true)
- {
- Console.WriteLine("\nNext input: ");
- var input = Console.ReadLine().Trim();
- if (input.ToLower() == "exit") break;
- Console.WriteLine(ConvertLength(input));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement