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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

String Exercises - Q3 Solution

Page history last edited by Steve Sweeney 11 years, 6 months 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.