I have a problem with the task. Firstly here are some guidelines for the task. Input of program: A natural number is loaded from the standard input first n and then n natural numbers each in a new line. Output of program:All loaded numbers divisible by 3 are printed in order on the standard output. Print each number in a separate line. Example I entered the numbers:
100
99
3
4
6
Each number must be in new line.
When I press enter the program must show me which numbers are divisible by 3. Example:
99
3
6
Here is my code
string a;
int n;
while (true)
{
a = Console.ReadLine();
if (a == string.Empty)
break;
n = Convert.ToInt32(a);
{
if (n % 3 == 0)
Console.WriteLine(n);
}
}
Problem is that when I enter a number that is divisible by 3 the program prints it immediately instead of waiting for me to finish entering numbers and only then to print numbers that are divisible by 3.