Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spaced number
#1
This is probably a simple problem, but here:
Code:
SCREEN 13
DIM map(1 TO 10, 1 TO 10)
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,1,1,1,1,1,1,1,1,1
FOR y = 1 TO 10
FOR x = 1 TO 10
  READ z
  map(x, y) = z
NEXT
NEXT
FOR y = 1 TO 10
FOR x = 1 TO 10
  IF x = 10 THEN
   PRINT map(x, y)
   ELSE
    PRINT map(x, y);
  END IF
NEXT
NEXT
How do I get it to stop printint spaces in between each number?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#2
Code:
PRINT LTRIM$(STR$(variable%))
Wink
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
LTRIM$(STR$(map(x, y)))

or rtrim$......................
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
Nope, LTRIM$. A space is reserved at the front of the string equiv of a number for a -ve sign.
Reply
#5
Ah, now I remember reading that! I never figured out why it added a space.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#6
By putting a PRINT after the FOR x loop, you can save yourself the IF ... THEN ... ELSE.
Code:
FOR y = 1 TO 10
FOR x = 1 TO 10
   PRINT map(x, y);
NEXT
PRINT
NEXT
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#7
Quote:By putting a PRINT after the FOR x loop, you can save yourself the IF ... THEN ... ELSE.
Code:
FOR y = 1 TO 10
FOR x = 1 TO 10
   PRINT map(x, y);
NEXT
PRINT
NEXT
I just needed to test whether a newline was needed, i.e. end of a row of the map. Notice that I put ";" on one of the PRINTs?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#8
they both do the same thing, its just that SCM does it a cleaner way.

yours goes through the x loop, and if x = 10, then it prints the number and then goes to the next line.

SCM's goes through the x loop, and then after it has gone through, it goes to the next line.

now if the x loop went to a number bigger than 10, but you still wanted it to print a new line at the 10th loop, then your way would be the only way.
url=http://webberboy.no-ip.com]Fine Hand-Crafted Pens[/url]
Pneumonoultramicroscopicsilicovolcanoconiosis: Noun, A hypothetical, invented disease of the lungs, caused by inhaling mineral or metallic dust, such as silicon and quartzite, over a long period.]
Reply
#9
I thought mine would be more efficient, because it avoids the IF statements being repeated. After I thought about it, I realized I had traded 10 IF's for 1 PRINT, and Print's are slow. I tested it both ways and found the performance to be the same. I agree that mine looks cleaner, but it doesn't work any better.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#10
I'm a geek Big Grin

Code:
FOR y = 1 TO 10
FOR x = 1 TO 10
   LOCATE y,x
   PRINT map(x, y)
NEXT
NEXT
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)