05-01-2003, 03:39 AM
Hi, i need help on a program that requires you to get a word or words from the user, and output the word(s) backwards...Any ideas?
A lie told often enough, becomes the truth"
Output backwards
|
05-01-2003, 03:39 AM
Hi, i need help on a program that requires you to get a word or words from the user, and output the word(s) backwards...Any ideas?
A lie told often enough, becomes the truth"
05-01-2003, 03:45 AM
well, an inefficient way off the top of my head
Code: function reverse$ (text$) i'm sure there's a better, faster way using sadd but if you arent whipping out hundreds of these a second it shouldnt matter.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
05-01-2003, 04:21 AM
Yes, that would work, but the teacher hasn't taught about fuctions and stuff, and she will fail u for using commands she didnt teach...were at a grade 10 level (if that helps your thinking)
A lie told often enough, becomes the truth"
05-01-2003, 05:22 AM
Just take off the function lines and it'll run once with the input provided in text$
Just for fun, I have a program that writes backwards as you type Code: DEFINT A-Z Kinda longer than the previously posted code, huh?
am an asshole. Get used to it.
05-07-2003, 12:41 PM
This is a bit shorter than the other solution...and doesn't involve a function. It does us an array, though. There are lots of ways to do this...this is just with a minute's thought.
CLS INPUT "input string"; a$ 'a$ is string z = LEN(a$) DIM temp(1 TO z) AS STRING * 1 FOR x = 1 TO z temp((z + 1) - x) = MID$(a$, x, 1) 'transfer a$ in reverse order to array temp() NEXT x a$ = "" 'clear a$ FOR x = 1 TO z a$ = a$ + temp(x) 'create new string with reverse order NEXT x PRINT a$
05-07-2003, 12:59 PM
Here's another bit of code that will reverse the letters...note it uses integer division to avoid dealing with the middle byte for strings with odd numbers of bytes...
CLS INPUT "input string"; word$ FOR x = 1 TO LEN(word$) \ 2 a$ = MID$(word$, x, 1) b$ = MID$(word$, 1 + LEN(word$) - x, 1) MID$(word$, x, 1) = b$ MID$(word$, 1 + LEN(word$) - x, 1) = a$ NEXT x PRINT word$ END |
« Next Oldest | Next Newest »
|