How to print accent in a Console Application .NET Core project [closed]

3
using System;

namespace MediaDoisNumeros
{
    class Program
    {
        static void Main(string[] args)
        {
            Int16 numero1, numero2;
            Double media;

            Console.Write("Digite o numero 1 : ");
            numero1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Digite o numero 2 : ");
            numero2 = Convert.ToInt16(Console.ReadLine());

            media = (numero1 + numero2) / 2;

            Console.WriteLine("A média dos dois numeros é {0}", media);
            Console.ReadKey();
        }
    }
}

Printed output on console:

The average age of the two numbers ├® 5

How to print correctly:

The average of the two numbers is 5

    
asked by anonymous 25.07.2017 / 01:43

1 answer

3

In order to print the accentuation it is necessary to define the encoding of the console output, so add Console.OutputEncoding = System.Text.Encoding.UTF8 at the beginning of your code.

Looking like this:

using System;

namespace MediaDoisNumeros
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Int16 numero1, numero2;
            Double media;

            Console.Write("Digite o numero 1 : ");
            numero1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Digite o numero 2 : ");
            numero2 = Convert.ToInt16(Console.ReadLine());

            media = (numero1 + numero2) / 2;

            Console.WriteLine("A média dos dois numeros é {0}", media);
            Console.ReadKey();
        }
    }
}
    
25.07.2017 / 12:42