+ 1

Almost got Name Buddy in C# but can't pass 5

namespace Sololearn { class Program { static void Main(string[] args) { string[] team = Console.ReadLine().Split(' '); string name = Console.ReadLine(); int i = 0; string named = " "; while (i < team.Length) { named = team[i]; i++; } if (name[0].Equals(named[0])) { Console.WriteLine("Compare notes"); } else { Console.WriteLine("No such luck"); } } } } It passes all the cases except number 5, which I can't see, so I'm not sure what its doing wrong or how to diagnose it. If anyone could help I'd appreciate it. I hate not being able to see all the cases. Also, is there a better/quicker way to do this?

23rd Dec 2021, 5:00 AM
Harley Wilkinson
Harley Wilkinson - avatar
2 odpowiedzi
+ 1
// try this string[] team = Console.ReadLine().Split(); string name = Console.ReadLine(); int i = 0, f = 0; while (i<team.Length) { if (name.Equals(team[i])) f++; i++; } if (f>0) Console.WriteLine("Compare notes"); else Console.WriteLine("No such luck");
23rd Dec 2021, 7:14 AM
SoloProg
SoloProg - avatar
0
Won't this only work if the entire name matches? I'm only trying to make sure that the first letter of name matches with the first letter of a string of names.
23rd Dec 2021, 9:29 PM
Harley Wilkinson
Harley Wilkinson - avatar