seems like this doesn't work as intended!

static void Main(string[] args) { Console.WriteLine("Welcome to our Words Counter"); Console.Write("Put your paragraphs here to get words number's count: "); string userInput = Console.ReadLine(); List<string> words = new List<string>(); string word = ""; for(int i=0; i<=userInput.Length-1;i++) { if (userInput[i]==' ') { if(!string.IsNullOrWhiteSpace(word)) { words.Add(word); word = ""; } } else { word += userInput[i]; } //Adds the last word if the input doesn't end with a space if (!string.IsNullOrWhiteSpace(word)) { words.Add(word); } } Console.WriteLine($"The ammount of words in your input are: {words.Count}"); Console.ReadLine(); } }
It just counts character while I made it to count words! unable to spot the issue haven't spent more than 3 minutes to spot but thought of sharing it over here! I am sorry for that
Was this page helpful?