2

I'm trying to create a fortress using slashes and dashes and I need to use a macron(overscore). I've tried a couple of ways but none of them worked. Any ideas how to make it work? Instead of Macron I get '?'

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

namespace kingsdom
{
    class Program
    {
       static void Main(string[] args)
       {
           int n = int.Parse(Console.ReadLine());
           string ups = new string ('^', n / 2);
           string midUps = new string('_' ,(n * 2) - (((n / 2) * 2) + 4));
           string whitespaces = new string(' ', (n * 2) - 2);
           string downs = new string('_', n / 2);
           string midDowns = new string('\u203E', (n * 2) - (((n / 2) * 2) +    4));
           Console.WriteLine("{0}{1}{2}{3}{0}{1}{2}", "/", ups, "\\", midUps);
           for (int i = 0; i < n - 2; i++)
           {
               Console.WriteLine("{0}{1}{0}", "|", whitespaces);
           }
           Console.WriteLine("{0}{1}{2}{3}{0}{1}{2}", "\\", downs, "/", midDowns);
       }
    }
}
NineBerry
  • 26,306
  • 3
  • 62
  • 93
VG98
  • 114
  • 1
  • 12
  • What is your problem exactly? Your code seems to work just fine to me. – Chris Feb 21 '17 at 16:46
  • @Chris Instead of Macron I get "?" – VG98 Feb 21 '17 at 16:48
  • That probably means that your font doesn't support the character. Try https://dotnetfiddle.net/DOyG5w which will hopefully work (your browser probably has unicode fonts). – Chris Feb 21 '17 at 16:50
  • Also consider editing your question to contain the details of your problem. The question should have a clear statement of what you expect to happen and what actually happened without people needing to search for the information in comments. It would certainly have saved me from wasting time compiling and running the code. – Chris Feb 21 '17 at 16:51
  • @Chris Is there a way to run it on my computer? – VG98 Feb 21 '17 at 16:57

1 Answers1

3

The console can use different code pages to display text. Not all of these code pages can display all characters correctly. For example, when you use the code page 855, which is the default for Windows systems using Eastern European languages with a Cyrillic alphabet, the Macron character cannot be displayed.

You can define what code page is used for your own console output by setting Console.OutputEncoding at the beginning of your Main function:

Console.OutputEncoding = Encoding.Unicode;

This will make it so that the console can display any Unicode character.

If you want to use a specific code page like for example 437 (US), you would write:

Console.OutputEncoding = Encoding.GetEncoding(437);

Note that using Encoding.Unicode at this place requires at least .net version 4.5.

See documentation of property Console.OutputEncoding for more details.

NineBerry
  • 26,306
  • 3
  • 62
  • 93