
-----------------------------------
scorpion1087
Thu Nov 06, 2003 1:10 pm

longest word in a sentence
-----------------------------------
i need to create a sentence an find the longest word in that sentence.
if you could give me a hand i would be thankfull.

this is my code so far

var SENT : string
put "enter a sentence"
get SENT : *
put "the total length is", length (SENT)

for i : 1 .. length (SENT)
    if SENT (i) = "" then
        put SENT (i - 1)
    end if
    put "the number of spaces is", SENT (i-1)    
end for

-----------------------------------
AsianSensation
Thu Nov 06, 2003 2:54 pm


-----------------------------------
ok, well first you have to break down your sentence into words.

run a for loop to break the sentence into words, and have a counter that keeps track of which one is the highest.

var sentence := "This is a sentence."
var word, highestword := ""
var highestnum := 0

for rep : 1 .. length (sentence)
    /*Count only letters*/
    if (sentence (rep) >= "A" and sentence (rep) = "a" and sentence (rep) 