hey

I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.

I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!

Any help getting started would be much appreciated

tom

Member Avatar for Micheus

hey

I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.

I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!

Any help getting started would be much appreciated

tom

You can count words in a sentance by looking for space character (or carrie return if present - Does is possible?) until the end of sentance (full stop ???). So, extracting word by word from sentance you can count how many letters it has in too.

If you need help getting started, These are Code Blocks I'd use:

To get the length of a string:

length(<somestring>)      {This gives you - have a guess - the Length of a string.}

To get only the string until the full stop:

var ct:Integer; somestring, croppedString:String; Flag:Boolean;
...
Begin
...
Flag := False;
ct:= 0;
While not Flag Do
   Begin
    Inc(ct);
    Flag := (somestring[ct] = '.') or (ct = length(somestring));        {somestring[2] gives you the 2nd letter of the string.}
   End;
croppedString:= copy(somestring, 1,ct);         {copy(String, Index, Count) gives you the "count" letters after "Index".}
...
End.

To count the number of letters:

var ct,NumOfLetters: Integer; somestring: String;
...
Begin
...
NumOfLetters := 0;
For ct:= 1 to length(somestring) Do
       If (somestring[ct] <> ' ') Then                 Inc(NumOfLetters);                  {Increase NumOfLetters.}
...
End.

I'll have to think about how to count the number of words with over three letters, though - I'll try to post it tomorrow.

Greetz

WhiteAvenger

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.