Posts: 9
Threads: 5
Joined: May 2003
Im in a Grade 10 Programming class, and the teacher hasn't gone into much detail about advanced programming, so with that in mind, how can you make a program that gets a word or words from the user, then outputs them backward...Keep in mind, she didn't teach much yet.
Thanx alot :king:
A lie told often enough, becomes the truth"
Posts: 1,166
Threads: 62
Joined: Apr 2003
Code: INPUT "Word to print backwards: ", text$
for n = len(text$) to 1 step -1
newtext$ = newtext$ + MID$(text$,n,1)
next
PRINT newtext$
Hmmm, maybe I should test that
**later**
yup it works.
am an asshole. Get used to it.
Posts: 3,368
Threads: 195
Joined: Jan 2003
I remember there was a topic on this in the newbie forum a while back.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 720
Threads: 46
Joined: Oct 2001
Quote:I remember there was a topic on this in the newbie forum a while back.
Perhaps there should be a section in the FAQ that lists the ten most common first-year compsci assignments... lol.
Posts: 2,020
Threads: 24
Joined: Jun 2002
same question. and nearly the same solution, except i think i put mine in a function and instead of n, named it x%.
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
Posts: 480
Threads: 24
Joined: Mar 2003
Code: INPUT "Enter string of text: ", text$
PRINT "That string, backwards, is: ";
FOR letter = LEN(text$) TO 1 STEP -1
PRINT MID$(text$, letter, 1);
NEXT letter
*peace*
Meg.
Posts: 2,020
Threads: 24
Joined: Jun 2002
i guess the ways to skin a cat are running thin
let's try sadd and poke this time around:
Code: INPUT text$
DEF SEG = VARSEG(text$)
os% = SADD(text$)
FOR x% = LEN(text$) - 1 TO 0 STEP -1
newtext$ = newtext$ + CHR$(PEEK(os% + x%))
NEXT x%
PRINT newtext$
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
Posts: 480
Threads: 24
Joined: Mar 2003
that previous post will reverse the letters in a single word. if you want your program to do THIS:
INPUT = "HELLO THIS IS A TEST OF MY PROGRAM"
OUTPUT = "PROGRAM MY OF TEST A IS THIS HELLO"
then try this code:
Code: INPUT "Enter text: ", text$
text$ = " " + text$ + " "
PRINT "Reversed: ";
location = LEN(text$)
DO
location = location - 1
IF MID$(text$, location, 1) = " " THEN
letter = location
DO
letter = letter + 1
letter$ = MID$(text$, letter, 1)
PRINT letter$;
LOOP UNTIL letter$ = " "
END IF
LOOP UNTIL location = 1
*peace*
Meg.
Posts: 2,020
Threads: 24
Joined: Jun 2002
good stuff meg, good stuff!
here, just to show you up,
Code: INPUT text$
x = 1
WHILE INSTR(x, text$ + " ", " ")
y = INSTR(x, text$ + " ", " ")
newtext$ = MID$(text$, x, y - x) + " " + newtext$
x = y + 1
WEND
PRINT newtext$
god bless that statement Now we need a program to reverse sentence order
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
Posts: 1,166
Threads: 62
Joined: Apr 2003
Quote:Agamemnus Wrote:I remember there was a topic on this in the newbie forum a while back.
Perhaps there should be a section in the FAQ that lists the ten most common first-year compsci assignments... lol.
Holy crap, I'm going into an AP computer science class next year (all year, 90 minutes a day) and I REALLY hope I don't get easy stuff like this. I may have to teach my teacher some things, lol. Of course, the class is now in Java, so I may not. Freaking stupid system... don't have smart enough kids for C++... *grumble grumble*
am an asshole. Get used to it.
|