Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grade 10 Programming
#1
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"
Reply
#2
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.
Reply
#3
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.
Reply
#4
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.
Reply
#5
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
Reply
#6
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.
Reply
#7
i guess the ways to skin a cat are running thin Smile

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
Reply
#8
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.
Reply
#9
good stuff meg, good stuff! Smile

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 Big Grin Now we need a program to reverse sentence order Smile
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
Reply
#10
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)