+ 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()); } } }
9 Answers
+ 4
Did you round UP? (i did the important word in caps).
+ 4
Remove all punctuation. Round up to the nearest whole number.
+ 3
I used this to count only letters:
if (Char.IsLetter(c))
If i comment it out the first test fails.
+ 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
+ 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()));
}
}
}
+ 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! ^^
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.
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()));
}
}
}
- 2
Ev