0

I dont know why my program close before i write numbers (in calculating option). And what is wrong with labels. Someone help ? Sorry for this. It's must be easy for you.

class Program
{
    static void Main(string[] args)
    {
        string str;
        double parametrA, parametrB, parametrC;
        Console.Write("Chose a option: \n");
        Console.Write("calculating - calculating square equation \n");
        Console.Write("series - even or odd \n");
        Console.Write("exit - close program \n");
        Console.ReadKey();
        while (true)
        {
            str = Console.ReadLine();
            if (str == "calculating")
            {
                goto label1;                     
            }
            else
            {
                if (str == "series")
                {
                    goto label2;
                }
                else
                {
                    if (str == "exit")
                    {
                        goto label3;
                    }
                }
            }

        label1:
            Console.WriteLine("calculating: \n");
            Console.WriteLine("enter parameters: \n");



            if (args.Length < 3)
            {
                Console.WriteLine("not enaught data \n");
                return;
            }
            try
            {
                parametrA = Double.Parse(args[0]);

                parametrB = Double.Parse(args[1]);

                parametrC = Double.Parse(args[2]);

//i shuld make a console.readkey()?

            }
            catch (Exception)
            {
                Console.WriteLine("One of the parameters isnt a correct number! ");
                return;
            }
            Console.WriteLine("Introduced equation parameters: \n");
            Console.Write("Parametr A = " + parametrA + "Parametr B = " + parametrB + "Parametr C = " + parametrC + "\n");
            if (parametrA == 0)
            {
                Console.WriteLine("It isn't a square equation! ");
            }
            else
            {
                double delta = parametrB * parametrB - 4 * parametrA * parametrC;
                double score;
                if (delta < 0)
                {
                    Console.WriteLine("Delta < 0! ");
                }
                else if (delta == 0)   
                {
                    score = -parametrB / (2 * parametrA);
                    Console.WriteLine("x = " + score);
                }
                else
                { 
                score = (-parametrB + Math.Sqrt(delta)) / (2 * parametrA);
                Console.WriteLine("x1 = " + score);
                score = (-parametrB - Math.Sqrt(delta)) / (2 * parametrA);
                Console.WriteLine("x2 = " + score);
                }

            }

If i separate labels, i can't compilate.

           label2:
                Console.WriteLine("odd numbers : \n");
                for (int i = 1; i <= 10; i++)
                {
                    if (i % 2 != 0)
                        Console.WriteLine(i);
                    else
                        Console.WriteLine("even!");
                }

This label work correct
label3: Console.WriteLine("exit \n"); if (str == "exit") { break; }

        }
     }
}

}

SebiX
  • 1
  • 1

1 Answers1

0

The following reads parameters from the program's command line arguments (the args array passed in to the main method.

parametrA = Double.Parse(args[0]);
parametrB = Double.Parse(args[1]);
parametrC = Double.Parse(args[2]);

What you probably want here are readLine calls as you've been using above.

EDIT: As for the compilation issue. Please post a properly formatted full example of the code that does not compile and do also post the compiler error as it will most likely say what's wrong with your code.