Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. static void Hashset()
  2.         {
  3.             HashSet<string> quizWords = new HashSet<string>();
  4.             for (int i = 0; i < 10; i++)
  5.             {
  6.                 Console.Write("Please type a word: ");
  7.                 string word = Console.ReadLine();
  8.                 if (quizWords.Contains(word))
  9.                 {
  10.                     Console.Write("Error: Word already added. ");
  11.                 }
  12.                 else
  13.                 {
  14.                     quizWords.Add(word);
  15.                     Console.Write("Word added. ");
  16.                 }
  17.             }
  18.  
  19.             Console.Clear();
  20.  
  21.             while (quizWords.Count > 0)
  22.             {
  23.                 Console.Write("Guess a word: ");
  24.                 string guess = Console.ReadLine();
  25.  
  26.                 if (quizWords.Contains(guess))
  27.                 {
  28.                     quizWords.Remove(guess);
  29.                     Console.WriteLine($"Correct \"{guess}\" removed");
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("Word not found. Try again.");
  34.                 }
  35.                 Console.WriteLine();
  36.             }
  37.             Console.WriteLine("All words guessed. Congratulations.");
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement