Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Recursion problem - Cambridge (International) question and answer I don't get

    I am including attachments of screen shots of both the question and the corresponding answers.

    What I don't get is why the Return Value is 'ETYB' and not 'YTEB'.

    I'd also love if someone could fix my code so that it produces the same answer as in the marks scheme (screen shot).

    Here is the code:

    Public Class Form1

    Function Y(ByVal s As String) As String

    Dim x As Integer = s.Length

    If x = 1 Then

    Return (s)
    Else

    Return Y(Microsoft.VisualBasic.Right(s, x - 1) + Microsoft.VisualBasic.Left(s, 1))


    End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim text As String = "BYTE"
    Dim answer As String
    answer = Y(text)
    End Sub
    End Class
    Attached Thumbnails Attached Thumbnails Recursion problem - Cambridge (International) question and answer I don't get-question-4-recursion.jpg   Recursion problem - Cambridge (International) question and answer I don't get-question-4-answers.jpg  

  • #2
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i would not exactly help you to fix the code but i can give you the hint
    Your problem is here. Check the parenthesis placements compared to the pseudo-code and you will see your problem
    Y(Microsoft.VisualBasic.Right(s, x - 1) + Microsoft.VisualBasic.Left(s, 1))

    and it has to give 'ETYB' has the output why change it??


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •