+ 3

Problem: Why does my code not work for Code coach "Average Word length"

I wrote that Code and used the first time List<>. I wrote the Base in VS Community and rewrote it in App but now some 'hidden' problems didn't get solved. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { public static List<int> count = new List<int>(); static void Main(string[] args) { string[] str = Console.ReadLine().Split(" "); foreach(string wrd in str) { count.Add(wrd.Count(x => wrd.Contains(x))); } Console.WriteLine("{0:0}", count.Average()); } } }

26th May 2022, 10:25 AM
Felix Alcor
Felix Alcor - avatar
9 Answers
+ 4
Did you round UP? (i did the important word in caps).
26th May 2022, 11:32 AM
Paul
Paul - avatar
+ 4
Remove all punctuation. Round up to the nearest whole number.
26th May 2022, 10:38 AM
JaScript
JaScript - avatar
+ 3
I used this to count only letters: if (Char.IsLetter(c)) If i comment it out the first test fails.
26th May 2022, 10:51 AM
Paul
Paul - avatar
+ 1
Shi Did you remove the spaces from the letter count. The spaces between letters is considered to be a character, which will be counted, and will skew your results
26th May 2022, 11:20 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { public static List<int> count = new List<int>(); static void Main(string[] args) { string[] str = Console.ReadLine().Split(" "); foreach(string wrd in str) { count.Add(wrd.Count(x => wrd.Contains(x).Equals(char.IsLetter(x)))); } Console.WriteLine(Math.Ceiling(count.Average())); } } }
26th May 2022, 11:49 AM
Felix Alcor
Felix Alcor - avatar
+ 1
I did already round Up and it still didn't Work. But thanks all of you, Paul and Jascript, I finished now and that because of you. My Problem got solved with isLetter and Math.Ceiling! ^^
26th May 2022, 11:49 AM
Felix Alcor
Felix Alcor - avatar
0
I already did round that's the meaning of "{0:0}" it force the whole number out. And I also did Math.Round() but didn't Work.
26th May 2022, 10:55 AM
Felix Alcor
Felix Alcor - avatar
0
I did try now with isLetter but now even less solutions got solved.. my code using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { public static List<int> count = new List<int>(); static void Main(string[] args) { int res = 0; string[] str = Console.ReadLine().Split(" "); foreach(string wrd in str) { char[] arr = wrd.ToCharArray(); for(int i = 0; i < wrd.Length; i++) { if(char.IsLetter(arr[i])) res++; } } count.Add(res); res = 0; } Console.WriteLine(Math.Round(count.Average())); } } }
26th May 2022, 11:26 AM
Felix Alcor
Felix Alcor - avatar
- 2
Ev
28th May 2022, 3:17 AM
Nwenyim Andrew
Nwenyim Andrew - avatar