平均単語長を計算しようとしましたが、エラーが表示され続けます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace textAnalyser
{
public class Analyser
{
public static void Main()
{
// Values
string myScen;
string newScen = "";
int numbChar = 0;
string userInput;
int countedWords = 0;
//User decsion on how to data is inputted
Console.WriteLine("Enter k for keyboard and r for read from file");
userInput = Convert.ToString(Console.ReadLine());
//If statement, User input is excecuted
if (userInput == "k")
{
// User enters their statment
Console.WriteLine("Enter your statment");
myScen = Convert.ToString(Console.ReadLine());
// Does the scentence end with a full stop?
if (myScen.EndsWith("."))
Console.WriteLine("\n\tScentence Ended Correctly");
else
Console.WriteLine("Invalid Scentence");
単語の文字数の計算
// Calculate number of characters
foreach (char c in myScen)
{
numbChar++;
if (c == ' ')
continue;
newScen += c;
}
Console.WriteLine("\n\tThere are {0} characters. \n\n\n", numbChar);
// Calculates number of words
countedWords = myScen.Split(' ').Length;
Console.WriteLine("\n\tTherer are {0} words. \n\n\n", countedWords);
これは、平均語長を計算しようとした場所です //Calculate Average word length
double averageLength = myScen.Average(w => w.Length);
Console.WriteLine("The average word length is {0} characters.", averageLength);`}