PDA

View Full Version : qbasic programming trouble (again)


ashykatia
03-04-03, 21:28
Hey there, long time no see, all. I want you all to know that helped me last time that the rounding trouble I had was easily recitified with a "PRINT USING" statement. Well, onward and upward.....
I am know in the deep throes of programming hell, and I welcome it, but this one has me pissed and aggravated.
I have to write a program that recognizes a palindrome.(same word OR sentence forward and backwards). I have the code witten what I thought was perfect. The first time I run the program, it turns out OK. But the next time through, it tells me the same word I had just entered isn't a palindrome. It has me unnerved. Here it what I have:

FOR count = LEN(palin$) to 1 step - 1
palin1$ = MID$(palin$, count, 1)+palin1$
NEXT
IF palin1$=palin$ THEN
PRINT"you have entered a palindrome"
ELSE
PRINT "nope, try again"
END IF

What did I do wrong????

Thanks....you are all great
;)

iamien
03-05-03, 00:58
Try having it read the entered word backwards, then testing for equality.

ashykatia
03-05-03, 14:01
I thought that's what the "step-1" did.

iamien
03-07-03, 01:45
sorry was a bit tierd when i posted, hmm dunno, i'll post if i see anything

lesrae
03-07-03, 07:29
Try changing the second line to read:

palin1$ = palin1$ + MID$(palin$, count, 1)

It seems to work, it's normal to add a variable to itself in this order, not as you have it.

For a visual check, print both of the strings after your NEXT command:

print palin$
print palin1$