mercredi 11 décembre 2019

How can i fix this code that, when running, don't do anything?

Well im trying to do a simple code in c# with nothing more than some if statements, but for some reason i don't understand the code compile but don't lem me interact with. The console window keep black and when i press some key nothing happens. The code:

        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.

The "root" method up there is this one:

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
    }

The variables "a", "b" and "c" have respectively the values 1, -20 and 51. I tried to change the delta declaration of place, but it doesn't worked. How can i solve this problem? (sorry if i said something wrong in english)

Aucun commentaire:

Enregistrer un commentaire