Update Lesson 1 Task 3

This commit is contained in:
Stanislav Mykhailenko 2023-03-19 14:03:57 +02:00
parent 62266346ac
commit 49969a1b5f
GPG key ID: 1E95E66A9C9D6A36

View file

@ -9,27 +9,31 @@ List<int> numbers = new List<int>();
for (int i = 0; i < 10; i++)
{
int newNumber;
int newNumber;
do
{
Console.Write($"Enter number {i + 1}: ");
} while (!int.TryParse(Console.ReadLine(), out newNumber));
while (true)
{
Console.Write($"Enter number {i + 1}: ");
if (int.TryParse(Console.ReadLine(), out newNumber))
break;
}
numbers.Add(newNumber);
numbers.Add(newNumber);
}
do
while (true)
{
Console.Write("Enter a number to duplicate: ");
} while (!int.TryParse(Console.ReadLine(), out duplicate));
Console.Write($"Enter number to duplicate: ");
if (int.TryParse(Console.ReadLine(), out duplicate))
break;
}
for (int i = 0; i < numbers.Count; i++) {
if (numbers[i] == duplicate)
{
numbers.Insert(i, duplicate);
i++;
}
if (numbers[i] == duplicate)
{
numbers.Insert(i, duplicate);
i++;
}
}
Console.WriteLine(String.Join(", ", numbers));