首页 > 解决方案 > 我怎样才能修复这个在运行时什么都不做的代码?

问题描述

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

        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。我试图更改 place 的 delta 声明,但没有成功。我怎么解决这个问题?(对不起,如果我用英语说错了)

标签: c#if-statementvariables

解决方案


你忘记了 Console.ReadLine();


推荐阅读