logo CodeStepByStep logo

StartEndLetter

Write a subroutine named StartEndLetter that accepts a character (Char) as a parameter. The subroutine repeatedly prompts the user to enter console input until the user types two consecutive words that both start and end with that letter for example, the word "shells" starts and ends with "s"c. The subroutine then prints a message showing the last word typed.

Your code should be case-insensitive for example, if the character passed is the lowercase "t"c, you should also consider it a match if the user types a word that starts and ends with an uppercase "T"c. If the user types a one-letter word, that word is considered to start and end with its single letter. For example, the word "A" starts and ends with "a"c.

The following log represents the console output from a call to your subroutine. (User input is shown like this.) Your subroutine should exactly match the output structure and behavior shown below when given similar input.

StartEndLetter("s"c)
Looking for two "s" words in a row.
Type a word: I
Type a word: love
Type a word: CS
Type a word: students
Type a word: PROGRAMS
Type a word: SCISSORS
Type a word: melon
Type a word: pens
Type a word: Q
Type a word: scores
Type a word: SOS
"s" is for "SOS"

Assumptions: You may assume that the parameter value passed will be a lowercase letter from "a"c to "z"c inclusive. You may also assume that the user will type a valid single-word response to each prompt and that the word will contain at least one character (the user will not type a blank line).

Constraints: You should not use any data structures such as lists to help you solve this problem. You may declare as many simple variables such as integers or strings as you like.

Function: Write a VB function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.