|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Newbie needs help
ok, here is my problem, I am in a grade 12 programming class and I am stuck on something so simple its stupid but my problem is that I just cant wrap my mind around it. Here is the program I have to make:
The user must input a sentence and the program must check and see if the sentence is the same backwards and fowards. for example: I am therefore am I <---- that is the same back and forth I am stuck here, I would really appreachate it if I got some help on this. I just want to understand this stuff. All Help would be really appreachated Thanks |
|
#2
|
|||
|
|||
|
Quote:
Wow, not entirely sure what you're looking for, I was thinking palindrome originally,but it seems not. I'll explain both. Not entirely sure what your teacher is looking for, and in no way am I going to do your homework for you. But I will explain a way to do it. The Palindrome Ex: racecar reversed is the same word, racecar You could use a textbox for your user input, and from that loop through backwards (or forwards if you wanted, but it's less confusing backwards) and make a new string of the reversed characters and compare them with if x1 = x2. Pseudo: user input for loop from len x to 1, with a step of -1 newstring = newstring + place of userinput with the loop iteration next if user input = newstring win else lose -------------------------------------------------- What you seem to be saying Ex: I am therefore am I You could use a textbox for user input, seperate with words delimiting by spaces, loop through backwards and make a new string with the words reversed, then use if x1 = x2, when rearranging the words, make sure to readd the spaces, and make sure you don't add a space on the last word of the loop. Pseudo: user input delimit by space, get an array for loop to upper of the array, to lower of array, step -1 check to see if you're at the lower of the loop if yes new string = new string + word(step) if no new string = newstring + word(step) + space next if user input = new string win else lose |
|
#3
|
||||
|
||||
|
Like Alias-Zero, I dont like writing your homework for you but your question got my attention and I wanted to find a slick way of doing it. Alias-Zero's logic is spot on, but I wanted to demonstrate a slightly different approach which doesn't involve concatenating the strings, instead, use Split make the string into an array (you can specify what character to use as the delimiter when using split eg. Split(astring, "|") but it defaults to a space!!), then compare the first element of the array with the last, the second with the second last etc...:
Code:
Dim a, b As Integer
Dim strArray() As String
Dim isOK As Boolean
Private Sub Command1_Click()
strArray = Split(Text1.Text)
b = UBound(strArray)
isOK = True
For a = 0 To UBound(strArray)
If Trim(UCase(strArray(a))) <> Trim(UCase(strArray(b))) Then isOK = False
b = b - 1
Next
If isOK Then
MsgBox "ok"
Else
MsgBox "incorrect"
End If
End Sub
|
|
#4
|
|||
|
|||
|
thank you guys I dont like homework being done for me either I like to learn things on my own thank you guys for all your help here
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Newbie needs help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|