/
NumbersFrom1toN.cs
54 lines (48 loc) · 1.38 KB
/
NumbersFrom1toN.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
namespace NumbersFrom1toN
{
internal class NumbersFrom1toN
{
private static void Main(string[] args)
{
#region Tests
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Testing with variables from the examples!\n");
int[] testInts = new int[] { 3, 5, 1 };
foreach (int item in testInts)
{
Console.WriteLine("Input: {0}", item);
printNumbers(item);
Console.WriteLine();
}
Console.WriteLine("Test End!\n");
Console.ForegroundColor = ConsoleColor.White;
#endregion Tests
Console.Write("How many numbers do you want to print?:");
printNumbers(getInput());
}
private static void printNumbers(int x)
{
for (int i = 1; i <= x; i++)
{
Console.WriteLine(i);
}
}
private static int getInput()
{
int number;
do
{
if (int.TryParse(Console.ReadLine(), out number))
{
break;
}
else
{
Console.Write("Invalid input,try again: ");
}
} while (true);
return number;
}
}
}