4

Code:
This program checks if the 2 numbers entered and their sum are divisible by the numbers 2 - 9, and displays the remaining divisible numbers (excluding the one being reviewed).

static void Main(string[] args)
{
    for (int i = 2; i < 10; i++)
    {
        Challenge(2, 6, i);
    }
    Console.ReadLine();
}

static void Challenge(int num1, int num2, int Divisor)
{
    int sum = num1 + num2;
    bool SumDivisible = sum % Divisor == 0;
    bool num1Divisible = num1 % Divisor == 0;
    bool num2Divisible = num2 % Divisor == 0;

    int highNum = 80;
    List<int> NumbersDivisible = Enumerable.Range(1, highNum).Where(x => x % Divisor == 0).ToList();

    // Use the booleans to determine output.
    if (SumDivisible || num1Divisible || num2Divisible)
    {
        if (SumDivisible)
        {
            Console.WriteLine("The SUM ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", sum, Divisor);
            outputListExceptInt(NumbersDivisible, sum);
            //output
            Console.WriteLine("\n\n");
        }
        if (num1Divisible)
        {
            Console.WriteLine("The FIRST number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num1, Divisor);
            outputListExceptInt(NumbersDivisible, num1);
            //output
            Console.WriteLine("\n\n");
        }

        if (num2Divisible)
        {
            Console.WriteLine("The SECOND number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num2, Divisor);
            outputListExceptInt(NumbersDivisible, num2);
            //output
            Console.WriteLine("\n\n");
        }
    }
    else
    {
        Console.WriteLine("The NUMBERS chosen and their SUM are not divisble by {0}. \nThe USABLE numbers for {0} are:\n", Divisor);
        outputListExceptInt(NumbersDivisible);
        Console.WriteLine("\n\n");
    }
}

public static void outputListExceptInt(List<int> NumbersDivisibleByDivisor, int except = 0)
{
    var Numbers = except > 0 ? NumbersDivisibleByDivisor.Where(x => x != except) : NumbersDivisibleByDivisor;
    foreach (int num in Numbers)
    {
        Console.WriteLine(num);
    }
}

Problem:
I'm finding that when I set the range (highNum) to anything over 89, a noticeable portion from the top of the window gets cut off:

highNum = 89:
highNum at 89

highNum = 90:
highNum at 90

Its cutting off 6 lines just with that small jump, and I'm not sure why.

Question:
My best guess is that there must be some limit on the output that can be displayed by the Console Window. Is this correct, or is something else causing this issue?

Community
  • 1
  • 1
ITSUUUUUH
  • 189
  • 1
  • 3
  • 18
  • 1
    In your window alt-space P go to layout and change the screen buffer size, this is how many lines the console will have when you scroll up. – Darryl Braaten Dec 08 '15 at 16:28
  • 1
    The Windows console always had a limit which can be changed eg by the command line window's options. If you want to preserve the text though, write it to a file. You can't depend on the user setting it large enough to suit your application – Panagiotis Kanavos Dec 08 '15 at 16:29
  • 1
    When displaying too many results: use `Write` instead of `WriteLine` (with some padding, e.g. `num.ToString().PadLeft(10,'0')`) or paginate output (wait for keypress after every 40 outputs). – Sinatr Dec 08 '15 at 16:32
  • 3
    I think the default buffer-height is 300. You can adjust the buffer- and window-size using Console.SetBufferSize(...) and Console.SetWindowSize(...) – Mark Dec 08 '15 at 16:32
  • @Sinatr I appreciated the C# fix. **Write** gets me to highNum 95 on its own. I will be implementing the paginate features later as you suggested. Just wish you had submitted yours as an answer... – ITSUUUUUH Dec 08 '15 at 17:03
  • Possible duplicate of [More lines in command window](https://stackoverflow.com/questions/1740876/more-lines-in-command-window) – Rand Random Apr 30 '18 at 15:06

3 Answers3

11

In a console window, click on Defaults

enter image description here

This opens a dialog box that allows you to set the scrollback buffer size (max number of lines to retain) by default in all of your console windows.

enter image description here

In my screenshot it is set to 9000 because I often log output to a console, and sometimes need to be able to scroll way back.

You can also modify it from your program for the console it is running in using Console.SetBufferSize().

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • Thanks! I'm utilizing the Console.SetBufferSize() method as I want it to be specific to my program. This specifically did the trick for me (where highNum = 100): **Console.SetBufferSize(Console.BufferHeight, 400);** – ITSUUUUUH Dec 09 '15 at 14:53
5

Yes, the console has a width and height limit. And you can change it:

Screen height

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
2

Answer modified from what's given here on microsoft's website:

  • Click the upper-left corner of the Command Prompt window, and then click Properties.
  • Click the Layout tab.
  • In Screen Buffer Size, type or select 2500 in Height.
  • Save the props by pressing OK.

You just have small buffer.

displayName
  • 13,888
  • 8
  • 60
  • 75