HELP C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

HELP C#

I just need help understanding the assignment and what I need o correct. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { HashSet<string> candidates = new HashSet<string>(); candidates.Add("John"); candidates.Add("Amelie"); candidates.Add("Tom"); candidates.Add("Richard"); candidates.Add("Barbara"); candidates.Add("Susan"); candidates.Add("Charles"); candidates.Add("Daniel"); candidates.Add("Tamara"); candidates.Add("Donald"); HashSet<string> hiring = new HashSet<string>(); while (hiring.Count<3) { string hire = Console.ReadLine(); //add the names to hiring hash set candidates.Add(Console.ReadLine(hiring)); } //your code goes here if(hiring.IsSubsetOf(candidates)) { Console.WriteLine("Starting hiring process"); } else { Console.WriteLine("Something is wrong"); } } } }

29th Nov 2021, 4:50 AM
Chris
Chris - avatar
6 Answers
+ 2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { HashSet<string> candidates = new HashSet<string>(); candidates.Add("John"); candidates.Add("Amelie"); candidates.Add("Tom"); candidates.Add("Richard"); candidates.Add("Barbara"); candidates.Add("Susan"); candidates.Add("Charles"); candidates.Add("Daniel"); candidates.Add("Tamara"); candidates.Add("Donald"); HashSet<string> hiring = new HashSet<string>(); while (hiring.Count<3) { string hire = Console.ReadLine(); //add the names to hiring hash set hiring.Add(hire); } //your code goes here Console.Write(hiring.IsSubsetOf(candidates)? "Starting hiring process":"Something is wrong"); } } }
26th Aug 2022, 9:22 PM
Victor Vidal
Victor Vidal - avatar
+ 1
Brittany Ridley It's great that you have attached your code, but what is the expected output vs input
29th Nov 2021, 6:04 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Brittany Ridley Is this challenge 79.3, Hiring Engineers?
29th Nov 2021, 6:07 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Brittany Ridley Thanks for getting back with this info. The problem you had was that the challenge requires you to Add the value "hire" into the hashset "hiring" 3 times as per the while loop. You were trying to use the readLine method 3 times to add to the hashset candidates. The rest of your code is excellent as it takes the items within the hashset "hiring" & compares it as a subset to the hashset "candidates" with the appropriate outputs. This little adaptation to your code may help while (hiring.Count<3) { string hire = Console.ReadLine(); //add the names to hiring hash set hiring.Add(hire);
30th Nov 2021, 6:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thank you for your help!
30th Nov 2021, 4:16 PM
Chris
Chris - avatar
0
Hey, I just got home from work. Here is the expect out come. We are hiring programmers on our team. There are 10 candidates, and we need to choose 3 of them. In the program you are given, you have 10 candidates in a hash set. You need to take 3 names as input, add them to a new hiring hash set and check if they are present in our candidates set. If they are, the program should output "Starting hiring process", otherwise, "Something is wrong". Sample Input John Susan Daniel Sample Output Starting hiring process IsSubsetOf() returns true if the hash set is a subset of the specified collection.
30th Nov 2021, 3:54 AM
Chris
Chris - avatar