F
F
FogEast2020-12-31 22:54:07
C++ / C#
FogEast, 2020-12-31 22:54:07

.exe is not fully executed. What to do?

So, I'll start by saying what kind of C# study I sat down tonight, and understandably - I had a problem. It lies in the fact that the exe file is not fully executed. After I enter the second number, the program closes. At what without debugging of such problem is not present.
Tell me what's wrong.

Happy New Year!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Сalculator
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            int a, b;
            
            Console.WriteLine("Введите первое число:");
            str = Console.ReadLine();
            a = Convert.ToInt32(str);
            Convert.ToInt32(a);

            Console.WriteLine("Введите первое число:");
            str = Console.ReadLine();
            b = Convert.ToInt32(str);
            Convert.ToInt32(b);
            
            int result1 = a + b;
            int result2 = a - b;
            int result3 = a * b;
            int result4 = a / b;
            Console.WriteLine("Сумма: " + result1);
            Console.WriteLine("Разность: " + result2);
            Console.WriteLine("Произведение: " + result3);
            Console.WriteLine("Частное: " + result4);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2020-12-31
@FogEast

Console.ReadKey() needs to be added to the end of the Main function.
The console closes, because after you have entered all the necessary data, nothing holds it.
By adding Console.ReadKey() to the end, the console will wait for you to press any button on the keyboard.
Now, if you run your application immediately in the console from the folder where the project is located, then it will not close itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question