Hello, I’m working on this task:
It is time for Simon to organize his team. He wants to rearrange the order of people so that the most inexperienced are in the front, and experienced - in the back of the group. He decided to determine the experience by age.
Write a program that reads team members ages from the console, each from the new line, until the input is “done”. Put each integer in the the list. Sort the list, and output all the integers in the ascending order, each from a new line.
Example:
>28
>17
>54
>47
>done
17 28 47 54
Here is my code:
using System.Collections.Generic;
namespace Lists
{
public class RearrangeTheTeam
{
static void Main(string[] args)
{
List<int> ages = new List<int>();
bool isListNotDone = true;
while(isListNotDone)
{
string input = Console.ReadLine();
int num;
if(input == "done")
isListNotDone = false;
else
{
num = int.Parse(input);
ages.Add(num);
}
}
ages.Sort();
foreach(int i in ages)
{
Console.Write($"{i} ");
}
}
}
}
Can anyone please help me to solve it?