+ 2
ماالخطأ في كودي لهذه المسألة؟
The program you are given defines an array with 10 words and takes a letter as input. Write a program to iterate through the array and output words containing the taken letter. If there is no such word, the program should output "No match".
9 Answers
+ 3
Zina Shekh Alzoor
1.Remove counter "count" as you use foreach loop so no need for counter
2."WriteLine" L is Capital so replace it
3. there is semicolon ; at the end of
string []words ...
+ 3
Zina Shekh Alzoor
Print matched value and increment count
Outside the loop print "No match" if count is 0
count == words.Length will give "no output" message because count would not be equal to words.Length untill all value doesn't match
string letter = Console.ReadLine();
int count = 0;
//your code goes here
foreach (string k in words) {
if (k.Contains(letter)) {
Console.WriteLine(k);
count++;
}
}
if (count == 0)
Console.WriteLine("No match");
+ 1
int count++; is invalid. Just put count++; in else part.
After the loop, If count is equal to array words length then output "No match" It's means never if part executed..
+ 1
string letter = Console.ReadLine();
int count =0;
//your code goes here
foreach (string k in words )
{
if (k.Contains(letter))
{
Console.WriteLine(k);
}
else count ++;
}
if (count==words.length)
{
Console.WriteLine("No match");
}
+ 1
using System;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string[] words = {
"home",
"programming",
"victory",
"C#",
"football",
"sport",
"book",
"learn",
"dream",
"fun"
};
string letter = Console.ReadLine();
//your code goes here
foreach (string k in words )
{
if (k.Contains(letter))
Console.WriteLine(k);
else
Console.WriteLine("No match");
}
}
}}
+ 1
Thanks👌
0
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
foreach (string k in words )
{
if (k.Contains(letter))
Console.Writeline(k);
else
Console.Writeline("No match");
}
int count ++
}
}
0
string letter = Console.ReadLine();
int count =0;
//your code goes here
foreach (string k in words )
{
if (k.Contains(letter))
{
Console.WriteLine(k);
count ++;
}
هكذا؟
else if (count==words.length)
{
Console.WriteLine("No match");}
0
Yes. This AJ solution is cool.. I followed your approach.