| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 137824 | 2014-08-24 05:13:00 | Help with pseudocode and Visual Basic 2010 | sportyguy1 (17290) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1382375 | 2014-08-24 05:13:00 | I am trying to make this Visual Basic code output a recursive answer, but it does nothing . Public Class Form1 Function Y(ByVal s As String) As String Dim x As Integer = s . Length 06 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 |
sportyguy1 (17290) | ||
| 1382376 | 2014-08-24 05:29:00 | 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 I ran the code and got a StackOverflow exception. After stepping through the code, it seems as if all it's doing is moving the first letter to the end but not actually shortening the string, causing an infinite loop. What's the code supposed to do? |
pcuser42 (130) | ||
| 1382377 | 2014-08-24 06:59:00 | Did you see the marking schedule I attached. It looks like it's supposed to reverse the STRING that's entered, so in this case BYTE becomes ETYB. | sportyguy1 (17290) | ||
| 1382378 | 2014-08-24 07:46:00 | There isn't an attachment :confused: | pcuser42 (130) | ||
| 1382379 | 2014-08-24 08:44:00 | docs.google.com docs.google.com |
sportyguy1 (17290) | ||
| 1382380 | 2014-08-24 08:46:00 | drive.google.com drive.google.com |
sportyguy1 (17290) | ||
| 1382381 | 2014-08-24 09:42:00 | I'm sure someone will give you some pointers but they won't do your homework for you. It won't be me I can't code to save myself. | gary67 (56) | ||
| 1382382 | 2014-08-24 10:43:00 | it's okay I finally got a programmer to walk me through the pseudocode line by line and it sort of makes sense, but not. He did say that most good programmers don't use recursion, but a lot of people are afraid of it. |
sportyguy1 (17290) | ||
| 1382383 | 2014-08-24 11:15:00 | He did say that most good programmers don't use recursion, but a lot of people are afraid of it. Given the importance and capability of recursive procedures, any good programmer will be well-versed in recursion and will understand when it is (and isn't) the solution. It's one of the key procedural areas of computer science. Your code given doesn't appear to have any termination condition, other than giving it an initial string of length 1. It needs to know when to stop. |
inphinity (7274) | ||
| 1382384 | 2014-08-28 00:23:00 | Given the importance and capability of recursive procedures, any good programmer will be well-versed in recursion and will understand when it is (and isn't) the solution. It's one of the key procedural areas of computer science. Your code given doesn't appear to have any termination condition, other than giving it an initial string of length 1. It needs to know when to stop. and a bit of fault checking ie want happens if you have an empty string ie nothing entered |
beama (111) | ||
| 1 | |||||