QUOTE(Sothrie @ 29 Jan, 2008 - 08:06 AM)

Usually when you work with arrays, the Length function returns the actual length of the array, as opposed to the zero based index that we're used to working with. So I would bet that if you were to walk through your code, your for loop would be coming up with this error on the last loop through that for loop. Try replacing wordList.length with wordList.length - 1
CODE
for (i = 0; i <= wordList.Length - 1; i++)
Hope this helps!
Hi Sothrie'
Thank's very much.
it's solve almost averything.
one last problem...
when he ask : "Do you want to analyse another sentence (Y/N)? "
when i click "y" nothing happen
do u know why?
neve mind.
i solved it
thank u for all the help
here is the code that works fine:
CODE
using System;
using System.Collections.Generic;
using System.Text;
// This program is Assignment 4 for Software Development 1 2006/2007.
//
// The program prompts the user to enter sentences. It will then analyse
// them to give a total word count, the number of non-white space characters,
// plus a count of how many words there are of length 1, 2, 3, 4, 5 and 6 or greater.
namespace Assignment4
{
class WordCount
{
static void Main(string[] args)
{
string sentence;
string[] wordList;
string word;
int[] sizeCount = new int[6];
int i;
int characterCount = 0;
string runAgain;
bool continueRunning = true;
Console.WriteLine("The program will analyse sentences you type in.");
while (continueRunning == true)
{
for (i = 0; i <= 5; i++)//correction: expected ";"
{
sizeCount[i] = 0;
}
Console.WriteLine();
Console.Write("Please enter a sentence: ");
sentence = Console.ReadLine();
while (sentence.Length == 0)
{
Console.Write("You must enter some text. Please try again: ");
sentence = Console.ReadLine();
}
Console.WriteLine();
wordList = sentence.Split(new char[] { ' ' });
Console.WriteLine("The number of words in the sentence is " + (wordList.Length - 1));// wordList.Length - 1 instead wordList.Length
for (i = 0; i <= wordList.Length - 1; i++)// wordList.Length - 1 instead wordList.Length
{
word = wordList[i].Trim();// correction:
if (word.Length > 0)
{
if (word.Length > 5)
{
sizeCount[0]++;
}
else
{
sizeCount[word.Length]++;// correction: "Length" and not "length"
}
characterCount = characterCount + word.Length;
}
}
Console.WriteLine("The number of words with 1 letter is " + sizeCount[1]);
for (i = 2; i <= 5; i++)// for i=2 insted i=1 becase 1 letter we alredy checked
{
Console.WriteLine("The number of words with " + i + " letters is " + sizeCount[i]);
}
Console.WriteLine("The number of words with 6 or more letters is " + sizeCount[0]);
Console.WriteLine("The number of non-white space characters is " + characterCount);
Console.WriteLine();
Console.Write("Do you want to analyse another sentence (Y/N)? ");
runAgain = Console.ReadLine().ToUpper();
while (runAgain != "Y" && runAgain != "N")
{
Console.Write("Please enter Y or N: ");
runAgain = Console.ReadLine().ToUpper();
}
if (runAgain == "N") // "N" insted of "Y"
{
continueRunning = false;
}
}
}
}
}