コード例 #1
0
        public void MyCode()
        {
            // The FIRST line of code should be BELOW this line

            CubeCalculator cc = new CubeCalculator();

            String userInput = cc.GetUserInput("Please enter an integer number:");

            while (cc.IsANumber(userInput))
            {
                if (cc.IsANumber(userInput))
                {
                    int value  = cc.ConvertToNumber(userInput);
                    int result = cc.CalculateCube(value);
                    Console.WriteLine("The cube of {0} is {1}", value, result);
                }
                else
                {
                    Console.WriteLine("Could not calculate...");
                }

                userInput = cc.GetUserInput("Please enter an integer number:");
            }



            // The LAST line of code should be ABOVE this line
        }
コード例 #2
0
        public void MyCode()
        {
            // The FIRST line of code should be BELOW this line

            CubeCalculator cc = new CubeCalculator(); //opretter et nyt objekt

            String userInput = cc.GetUserInput("Please enter a number or type 'done' to quit: ");

            while (userInput != "done")
            {
                if (cc.IsANumber(userInput))
                {
                    int value  = cc.ConvertToNumber(userInput);
                    int result = cc.CalculateCube(value);
                    Console.WriteLine($"The cube of {value} is {result}");
                }
                else
                {
                    Console.WriteLine("Could not calculate...");
                }
                userInput = cc.GetUserInput("Please enter a number or type 'done' to quit ");
            }



            // The LAST line of code should be ABOVE this line
        }
コード例 #3
0
        public void MyCode()
        {
            // The FIRST line of code should be BELOW this line

            CubeCalculator cc = new CubeCalculator();

            while (running)
            {

                String userInput = cc.GetUserInput("Please enter an integer number:");

                if (cc.IsANumber(userInput))
                {
                    int value = cc.ConvertToNumber(userInput);
                    int result = cc.CalculateCube(value);
                    Console.WriteLine("The cube of {0} is {1}", value, result);
                }
                else
                {
                    Console.WriteLine("Could not calculate...");
                }
            }
            // The LAST line of code should be ABOVE this line
        }