Computer Science Canada

book ends

Author:  scorpion1087 [ Tue Nov 11, 2003 12:53 pm ]
Post subject:  book ends

a book end is when you take a letter in a word and stop the word when you see the letter again. then show whats in the middle.

science-take the "C" therefore the word would be "cienc"
a skeleton for this would be great, thanks

Author:  Tony [ Tue Nov 11, 2003 7:00 pm ]
Post subject: 

umm... just use substrings to read each letter at the time. Maybe this will help?
code:

var word:string := "science"

for i:1..length(word)
put word(i)
end for

Author:  Dan [ Tue Nov 11, 2003 7:12 pm ]
Post subject: 

he is a fast thing i made up

code:

var worad : string
var letter : string
var newString : string := ""
var flag : boolean := false
var num : int := 0

put "put in wroad"
get worad

put "what letter to use for book end?"
get letter


loop
    num += 1

    if flag then
        newString += worad(num)
    end if
   
    if worad (num) = letter and flag = false then
            flag := true
            newString += letter
    elsif worad(num) = letter and flag then
            exit
    end if
   
    if num = length (worad) then
        exit
    end if
end loop

put ""
put "output: ", newString


you have to use substrings to readed each letter of the worad. this verson still has a few bugs but should give you an idea on how to do it


: