
-----------------------------------
Houdini
Thu Apr 02, 2009 6:37 pm

How to count 2 lettered words in sentence
-----------------------------------
I'm creating a program that allows you to type in a sentence and the output will be the total amount of words and how many 2-lettered words there are.. I'm not sure how to do the second part... I tried alot using two counters in my for loop but didn't work..  Here is the code I have so far: 


var sentence : string
var words : int := 1 

put "Please type in a sentence and hit enter"
get sentence : *

for x : 1 .. length (sentence)
    if sentence (x) = " " then
        words := words + 1
    end if
end for
put "There is a total of ", words, " words"


Mod Edit: Fixed the syntax tagsCode Here

-----------------------------------
tjmoore1993
Thu Apr 02, 2009 7:05 pm

RE:How to count 2 lettered words in sentence
-----------------------------------
I'm not sure if this will help but why not check out string manipulation tutorials?

-----------------------------------
saltpro15
Thu Apr 02, 2009 7:06 pm

RE:How to count 2 lettered words in sentence
-----------------------------------
maybe check the length of the word? for example

for i : 1..length(word)
counter +=1
end for
if counter >1 and counter = 'A' and sentence (i)  'a' and sentence(i) < 'z') then
    chars+=1
end if


Hope this helps!

-----------------------------------
Houdini
Fri Apr 03, 2009 2:39 pm

RE:How to count 2 lettered words in sentence
-----------------------------------
Thanks for the tips guys, will fix it and let you know if it works.
