public void Test1()
        {
            DecimalProgram DecimalToEverything = new DecimalProgram("10");
            string         result = DecimalToEverything.DecimalToHexa();

            Assert.That(result, Is.EqualTo("12"));
        }
Пример #2
0
        static void Main(string[] args)
        {
            MainProgram();

            void MainProgram()
            {
                Console.WriteLine("Type a number:");
                string input = Console.ReadLine();

                try
                {
                    ITheNumberSystem numberSystem;
                    if (input[0] == '0' && input[1] != 'x' && input[1] != 'X' && input[1] != ',')   //if number is octal
                    {
                        numberSystem = new OctalProgram(input);
                    }
                    else if (input[1] == 'x' || input[1] == 'X')  // if number is hexadecimal
                    {
                        numberSystem = new HexadecimalProgram(input);
                    }
                    else // if number is decimal
                    {
                        numberSystem = new DecimalProgram(input);
                    }
                    numberSystem.ShowResults();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                LoopOfMainProgram();//Re-loop the main program due to error
            }

            //ask the user if he wants to enter a new number
            void LoopOfMainProgram()
            {
                while (true)
                {
                    Console.WriteLine("Do you want to Convert another number? \n Type 'yes' or 'no'");
                    string answer = Console.ReadLine();
                    if (answer != "no")
                    {
                        if (answer == "yes")
                        {
                            Console.Clear(); MainProgram(); break;
                        }
                        else
                        {
                            Console.WriteLine("Wrong answer");
                        }
                    }
                    else
                    {
                        Environment.Exit(0); break;
                    }
                }
            }
        }
Пример #3
0
        public void ShowResults()
        {
            Console.WriteLine("In Octal: " + Number);
            Console.WriteLine("In Decimal: " + OctalToDecimal());
            string         Result = OctalToDecimal();
            DecimalProgram dec    = new DecimalProgram(Result);

            Console.WriteLine(dec.DecimalToBinary());
            Console.WriteLine(dec.DecimalToHexa());
        }
        public void ShowResults()
        {
            Console.WriteLine("In Hexadecimal: " + UserInput);
            Console.WriteLine("In Decimal: " + HexToDec());
            double         result         = HexToDec();
            DecimalProgram decimalSystems = new DecimalProgram(result.ToString());

            Console.WriteLine(decimalSystems.DecimalToBinary());
            Console.WriteLine(decimalSystems.DecimalToOctal());
        }