0

Average word length is not passing the test on sololearn. Please help

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string newWord = Console.ReadLine().Trim(); string []splitWord = newWord.Split(" "); float lengthOfEachWord = 0; int wordCount = splitWord.Length; float averageWord = 0; foreach (string word in splitWord){ lengthOfEachWord += word.Length; //Console.WriteLine(lengthOfEachWord); averageWord = lengthOfEachWord/wordCount; //Console.WriteLine(averageWord); } if (lengthOfEachWord % wordCount == 1){ Console.WriteLine(Math.Floor(averageWord)); //Console.WriteLine((int)averageWord); }else{ Console.WriteLine(Math.Ceiling(averageWord));

28th Feb 2021, 10:24 PM
Adewale Isaac
Adewale Isaac - avatar
4 odpowiedzi
+ 2
Adewale Isaac try removing, "if(lengthOfEachWord%wordCount==1) { Cons.. }" The code has asked only for rounding up not rounding down , so removing above might work.
28th Feb 2021, 10:35 PM
Abhay
Abhay - avatar
+ 1
Mention the language name in tags please
28th Feb 2021, 10:25 PM
Abhay
Abhay - avatar
0
C#
28th Feb 2021, 10:27 PM
Adewale Isaac
Adewale Isaac - avatar
0
Thanks but it is now allowing to pass the first test which is "Can you not do that?" Mine is giving the result of 4 while the expected result is 3.Kindly assist. Thanks
1st Mar 2021, 9:08 AM
Adewale Isaac
Adewale Isaac - avatar