+ 1

I'm doing the words code coach for C# and I can't figure out what I've done wrong

using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; //your code goes here while (count < words.GetLength) { if (words.Contains("letter")) { Console.WriteLine(words[count]) } else { Console.WriteLine("No match"); } count++ } } } }

18th Jan 2023, 4:32 AM
Brady Zab
Brady Zab - avatar
3 Respuestas
+ 4
(count < words.GetLength) //error words.Length if (words.Contains("letter"))//error a few errors 1 "letter" need letter 2 you need use words[] like that words[count].Contains.. so ok Console.WriteLine(words[count])//error 1 ...); dont forget to put ; 2 use break if found --snip -- WriteLine("No match");//error will output while not find in each iteration count++ //error, put ; shortly all code with errors..
18th Jan 2023, 5:31 AM
Smith Welder
Smith Welder - avatar
+ 3
Brady Zab Offhand, a ConsoleWriteLine and the count++ line are both missing the ;
18th Jan 2023, 5:03 AM
Scott D
Scott D - avatar
+ 3
Brady Zab the code is using the Contains method in the wrong way for this task. The task is to check each word within the words array to find which ones contain the input letter. You could use words[count] to index each word. The code is using the string literal, "letter" as the argument for Contains. Instead, it should be using the input variable, letter. Remove the double quotation marks. The code prints "No match" every time through the loop. The task is to print that string only if none of the words match. Move that output outside of the loop and add logic to detect when it should be printed.
18th Jan 2023, 5:35 AM
Brian
Brian - avatar