| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

String Exercises - Q3 Solution

Page history last edited by Steve Sweeney 15 years ago

var sentence : string

var lenSentence : int

var rangeOK : boolean       % true/false value

var low, high : int

 

put "Please enter a sentence"

get sentence : *    % want to allow spaces

lenSentence := length(sentence)

 

put "There are ", lenSentence, " characters in your sentence"

put "What range of characters to you want to output?"

 

rangeOK := false

loop

    put "From? : " ..

    get low

    if low >= 1 and low <= lenSentence then

        rangeOK := true

    else

        put "Invalid value for low end of range"

        put "Must be from 1 to ", lenSentence

    end if

    exit when rangeOK = true

end loop

 

rangeOK := false

loop

    put "To? : " ..

    get high

    if high >= low and high <= lenSentence then

        rangeOK := true

    else

        put "Invalid value for high end of range"

        put "Must be from ", low, " to ", lenSentence

    end if

    exit when rangeOK = true

end loop

 

put sentence(low .. high)

Comments (0)

You don't have permission to comment on this page.