Help needed for the 5th C# project. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help needed for the 5th C# project.

Please this is my attempt at a solution: 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(); for(int count=0;count<10;count++) { if (words[count].Contains(letter)) { Console.WriteLine(words[count]); } else { continue; Console.WriteLine("No match"); } } } } My problem deals with the "No match" code for no words found.

1st Nov 2021, 10:39 AM
Eugene Asare
Eugene Asare - avatar
16 Answers
+ 5
Eugene Asare you should save your code in the Sololearn playground and provide a link in your question, rather than pasting walls of code. That makes it easier to test and debug your code. Here is a working version based on the bool test that was suggested by [No Name] https://code.sololearn.com/coLNVD3GnQkJ/?ref=app
1st Nov 2021, 1:25 PM
Tibor Santa
Tibor Santa - avatar
+ 3
No match will never be executed, because you continue before. Try to continue after writing the line. Console.WriteLine(); continue;
1st Nov 2021, 11:03 AM
[No Name]
[No Name] - avatar
+ 1
Alright, thanks for the advice. I'll put it into practice
1st Nov 2021, 1:29 PM
Eugene Asare
Eugene Asare - avatar
+ 1
Thanks also for the assist with the code.
1st Nov 2021, 1:32 PM
Eugene Asare
Eugene Asare - avatar
+ 1
You should try testing for no match after the for loop completes.
3rd Nov 2021, 8:29 AM
Joel S. Jimenez
Joel S. Jimenez - avatar
0
Thanks for the input. I got to produce the "No match" text but the problem lies with generating words for those with letters appearing in them. For example: Case 1. for input letter 'l' The expected output is: football learn The code solution generated: No match No match No match No match football No match No match learn No match No match Case 2. for input letter 'z' Expected output is: "No match." The code solution generated: 10 elements of No match (i.e No match outputted ten times ) instead of a single output as expected. Would appreciate any further assistance
1st Nov 2021, 11:27 AM
Eugene Asare
Eugene Asare - avatar
0
Of course it prints the result for every time it runs through your loop. Just define a boolean variable out of the scope to check it like 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(); boolean check = false; for(int count=0;count<10;count++) { if (words[count].Contains(letter)) { check = true; Console.WriteLine(words[count]); } else { continue } If(!check) { // no result }
1st Nov 2021, 11:33 AM
[No Name]
[No Name] - avatar
0
Yes please ,got the concept . I'll try implementing it , and get back to you with the feedback .Thanks
1st Nov 2021, 11:39 AM
Eugene Asare
Eugene Asare - avatar
0
Still unsuccessful. Error message stating : The type or name space boolean could not be found .
1st Nov 2021, 11:52 AM
Eugene Asare
Eugene Asare - avatar
0
I think it's bool not boolean sorry 😂
1st Nov 2021, 11:53 AM
[No Name]
[No Name] - avatar
0
No prob, will try again
1st Nov 2021, 11:53 AM
Eugene Asare
Eugene Asare - avatar
0
It was a decent effort but problem with the no match output with the found text still persists. I had hope to segregate the two outputs using two for loops or nested for loops but the results keep affecting each other .
1st Nov 2021, 11:59 AM
Eugene Asare
Eugene Asare - avatar
0
Just set up a project here or on github and link it to me
1st Nov 2021, 12:06 PM
[No Name]
[No Name] - avatar
0
Could pls you walk me through how I would extract the project from and link it to you?
1st Nov 2021, 12:14 PM
Eugene Asare
Eugene Asare - avatar
0
Yeah, I attempted that at first but the bug still persisted
3rd Nov 2021, 8:35 AM
Eugene Asare
Eugene Asare - avatar
- 1
Actually fucked up the example because writing on my phone haha But you got my point
1st Nov 2021, 11:36 AM
[No Name]
[No Name] - avatar