我该如何修复运行时不做任何事情的代码?

时间:2019-12-11 21:06:31

标签: c# if-statement variables

我试图用简单的if语句在c#中做一个简单的代码,但是由于某种原因,我不理解代码的编译,但不允许我与之交互。控制台窗口保持黑色,当我按一些键时没有任何反应,它应该显示result的值(一两个取决于大小写)。 代码:

        int result1;
        int result2;
        int delta = (b * b) - 4 * a * b;
        //Declaration of the variables results and delta, the ones that will be used in the following block
        if ((a != 0) && (b != 0) && (c != 0))
        {
            if (delta == 0)
            {
                result1 = (-b) / (2 * a);
                Console.WriteLine(result1);
            }
            else if (delta > 0)
            {
                result1 = (-b + Root(delta)) / (2 * a);
                result2 = (-b - Root(delta)) / (2 * a);
                Console.WriteLine(result1);
                Console.WriteLine(result2);
            }
            else
            {
                Console.WriteLine("Sem resultado: delta menor que zero.");
            }
        }
        //In this if clause the code will verify the use of Bhaskara and the value of delta. Then execute the right count.

上面的“ root”方法是这样的:

static int Root (int radi) 
    {
        int rootTester = 0;
        int result;
        for (; ;)
        {
            rootTester++;
            if(rootTester * rootTester != radi)
            {
                continue;
            }
            else
            {
                break;
            }
        }
        result = rootTester;
        return result;
        //Here the compiler will try to multiplie a number for itself until this number will get equal the value of the radial
    }

变量“ a”,“ b”和“ c”分别具有值1,-20和51。 我试图更改位置的delta声明,但是没有用。 我怎么解决这个问题? (对不起,如果我用英语说错了)

1 个答案:

答案 0 :(得分:-1)

U忘记了 Console.ReadLine();

相关问题