Help me solve! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help me solve!

You are given a program that takes an array of 10 words and takes a letter as input. Write a program to iterate over an array and output words containing the letter received. If there are no matching words, the program should print "No match". Sample Input Data u Sample Output Data fun my attempt to solve the problem : https://code.sololearn.com/cAWH4n3SwyVJ/?ref=app But it's doesn't work 😞

13th Dec 2021, 9:09 AM
Mr.Mr
Mr.Mr - avatar
6 Answers
+ 1
Mr.Mr You declared count as int Then converted to String Checking count in letter Incrementing count. If count is converted to String then how you can increment it? learn again: 1 - data types and their uses 2 - foreach loop working behaviour
13th Dec 2021, 9:16 AM
A͢J
A͢J - avatar
+ 2
Mr.Mr Count is to check how many word has matching letter so if there are 2 or more than 2 matching words then count will be increase accordingly. So on the basis of count you can print "No match" if count is 0
13th Dec 2021, 2:35 PM
A͢J
A͢J - avatar
+ 1
Mr.Mr You have to print matched value not count. Print matched value and increase count. Outside the loop check if count is 0 then print "No Match"
13th Dec 2021, 9:11 AM
A͢J
A͢J - avatar
+ 1
Mr.Mr You have to check letter in each word of the given array. If match found then print word. Here is your solution. Check and find your mistakes: string letter = Console.ReadLine(); int count = 0; // count = Convert.ToString(); foreach(string str in words) { if(str.Contains(letter)) { Console.WriteLine(str); count++; } } if (count == 0) { Console.WriteLine("No Match"); }
13th Dec 2021, 9:17 AM
A͢J
A͢J - avatar
0
Understand
13th Dec 2021, 9:45 AM
Mr.Mr
Mr.Mr - avatar
0
I did not understand why "count" is here, so I inserted it into the foreach loop
13th Dec 2021, 9:49 AM
Mr.Mr
Mr.Mr - avatar