Dynamically changing top border line C# -


so i'm building multiplication table c# class. i've got code table complete, , works advertised. issue need dynamically changing top border, because table wide number user enters width digit, @ 5 character spacing. thoughts?

    static void main(string[] args)     {         int width, height;         //int tablewidth;          console.write("how wide want multiplication table? ");         width = convert.toint32(console.readline());          console.write("how high want multiplication table? ");         height = convert.toint32(console.readline());          console.write("    x|");          (int x = 1; x <= width; x++)             console.write("{0, 5}", x);               console.writeline();             (int row = 1; row <= height; row++)         {             console.write("{0, 5}|", row);             (int column = 1; column <= height; ++column)             {                 console.write("{0, 5}", row * column);             }             console.writeline();         }         console.readline();     } 

i assume tablewidth needs calculated, , console.write("_") equal width of total table. in advance :)

you need use loop, this:

console.write("how wide want multiplication table? "); int width = convert.toint32(console.readline()); console.write("how high want multiplication table? "); int height = convert.toint32(console.readline()); console.write("    "); (int = 0; < width; i++)      console.write("_____"); console.writeline("__"); console.write("    x|"); (int x = 1; x <= width; x++)     console.write("{0, 5}", x); console.writeline(); (int row = 1; row <= height; row++) {     console.write("{0, 5}|", row);     (int column = 1; column <= height; ++column)     {         console.write("{0, 5}", row * column);     }     console.writeline(); } console.readline(); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -