Execution console hangs while doing many reads in debug mode!

0

In order to debug the code for errors, many times I need to enter the requested data, but it is not always possible to reach the end of the program because the execution of the debug via "F10" or "F11" (if tell the difference) it blocks making it impossible to read the next data.

I do not know why this occurs and I did not find anything about it either. If you can help me with that, I'll be grateful.

Here is an image of the problem at runtime:

usingSystem;namespaceSomaMedia{classProgram{staticvoidMain(){stringnome_candidato=" ";
            int qt_eleitores = 0, qt_brancos = 0, qt_indecisos = 0, qt_intencoes;
            int cont = 0, maior = 0, menor = 0;
            double percentual_intencoes = 0, percentual_indecisos = 0, percentual_brancos = 0;
            int? cod_candidato = null;

            while (cod_candidato != 0)
            {
                Console.Write("QUANTIDADE DE ELEITORES: ");
                qt_eleitores = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("CÓDIGO DO CANDIDATO: ");
                cod_candidato = int.Parse(Console.ReadLine());
                Console.WriteLine();

                if (cod_candidato == 0)
                {
                    break;
                }

                Console.Write("NOME DO CANDIDATO: ");
                nome_candidato = Console.ReadLine();
                Console.WriteLine();

                Console.Write("INTENÇÕES DE VOTO: ");
                qt_intencoes = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("VOTOS EM BRANCO: ");
                qt_brancos = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("VOTOS INDECISOS: ");
                qt_indecisos = int.Parse(Console.ReadLine());
                Console.WriteLine();

                if (cont == 0)
                {
                    maior = qt_intencoes;
                    menor = qt_intencoes;
                }

                if (qt_intencoes > maior)
                {
                    maior = qt_intencoes;
                }

                if (qt_intencoes < menor)
                {
                    menor = qt_intencoes;
                }

                percentual_intencoes = ((qt_intencoes / qt_eleitores) * 100);
                percentual_brancos = ((qt_brancos / qt_eleitores) * 100);
                percentual_indecisos = ((qt_indecisos / qt_eleitores) * 100);

                Console.WriteLine($"{percentual_intencoes}% - {nome_candidato}");


            }

            Console.WriteLine($"{percentual_brancos}% - VOTOS EM BRANCO");
            Console.WriteLine($"{percentual_indecisos}% - VOTOS INDECISOS");

        }
    }
}
    
asked by anonymous 31.08.2018 / 22:14

1 answer

1

Ramon what is happening is not a problem but a poor understanding of running a program via the Visual Studio Console.

From your image I can see the yellow arrow , which indicates that your code is stopped at breakpoint waiting for you to continue debugging.

You said in the comments that you are required to press X to run the process again, but in fact what is happening is that the program is stopped at debug execution waiting for your interaction.

  

To solve your "problem", go back to the code and continue running your program by pressing F5, F10 or F11.

Function of F5

Continue running the program to the end or until you find an upcoming breakpoint in the algorithm flow.

F10 function

Performs line by line of the algorithm without entering methods that are along the stream. For example:

int numero = 0;

//Outros códigos que alteram o valor da variável numero

if (numero > 10)
{
    Calcular(numero);
}

If you press F10 when debugging is in the Calcular(numero) method, all the codes within the function will be executed, but we will not see what is happening inside it.

F11 Function

Performs line by line of algorithm, but in this case we enter methods that are along the stream. For example:

int numero = 0;

//Outros códigos que alteram o valor da variável numero

if (numero > 10)
{
    Calcular(numero);
}

If you press F11 when debugging is in the Calcular(numero) method, we will go through the definition of the Calculate method, and you can analyze what is happening in this algorithm flow interaction, analyzing the assignment of values, calls of other methods, executions of rules, etc.

    
31.08.2018 / 22:40