Please help me with the task: Checking if a list contains an item

Hello, I’m working on this task:

Simon is preparing for a raid on the C gang. He wants to choose the best team for this. Unfortunately, Simon can’t just assign the team members: this right in the C# gang belongs to the Council. Council chooses several people to form a team, and Simon has a veto rule: he either agrees to the selected group of people or not. Simon would agree only for the team where he is one of the members.
Write a program that reads from the console the names of people, each from the new line, until the input is “done”. Put each string into the list. If the list contains “Simon”, your program should output “Team accepted” otherwise “Team rejected”.

Example:
>Sintia
>Oliver
>Tom
>Simon
>Olivia
>done
Team accepted

Here is my code:

using System.Collections.Generic;

namespace Lists
{
   public class PrepareForTheRaid
   {
       static void Main(string[] args)
       {
           List<string> names = new List<string>();
           for (int i = 0; i < names.Count; i++)
           {   string name = Console.ReadLine();
               bool nameReal = true;
               while (nameReal)
               {
                   if(name != "done")
                   {
                   name = names[i];
                   }
                   else 
                   {
                   nameReal = false;
                   }
               }
           }
           bool listContainSimon = names.Contains("Simon");
           if (listContainSimon)
           {
               Console.WriteLine("Team accepted");
           }          
           else
           {   
               Console.WriteLine("Team rejected");
           }
       }
   }
}

Can anyone please help me to solve it?
After my code it outputs: Team rejected

та сама помилка, що тут: Please help me with the task: Checking if a list contains an item - #3 by Olena_CWLm :slight_smile:

Дякую! все вийшло :smile: І програма більше не підвисає

1 Like