` ANTIC VOL. 2, NO. 2 / MAY 1983`

# Positive, Negative or Zero

by Bob Albrtcht and George Firedrake

DragonSmoke poses problems for you to ponder, questions for you to answer, programs for you to write, and whatever other mischief we might cunningly contrive. As time goes on, and as issue follows issue, we will answer some of the problems we create. Better yet, you answer.

## Positive, Negative, Or Zero

An easy problem. All we want is a program that asks for a number, then tells you something about the number.

If you enter a positive number, the computer tells you: YOUR NUMBER IS POSITIVE

If you enter a negative number, the computer tells you: YOUR NUMBER IS NEGATIVE

If you enter the number zero (0), the computer tells you: YOUR NUMBER IS ZERO

A RUN might go like this:

ENTER A NUMBER AND I'LL TELL YOU WHETHER YOUR NUMBER IS POSITIVE, NEGATIVE OR ZERO
YOUR NUMBER ? and so on

We know at least seven ways to write this program. Here is an obvious way.

100 REM ** POSITIVE, NEGATIVE, OR ZERO
110 DIM YN\$(15), N\$(8), Z\$(4), P\$(8)
120 YN\$ = "YOUR NUMBER IS "
130 N\$ = "NEGATIVE"
140 Z\$ = "ZERO"
150 P\$ = "POSITIVE"
200 REM ** TELL WHAT TO DO
210 PRINT CHR\$(125)
220 PRINT "ENTER A NUMBER AND I'LL TELL"
230 PRINT "YOU WHETHER YOUR NUMBER IS"
240 PRINT "POSITIVE, NEGATIVE, OR ZERO."
300 REM ** ASK FOR A NUMBER
310 PRINT
320 PRINT "YOUR NUMBER";: INPUT X
410 IF X< 0 THEN PRINT YN\$;N\$
420 IF X = 0 THEN PRINT YN\$; Z\$
430 IF X > 0 THEN PRINT YN\$; P\$
500 REM ** GO FOR ANOTHER NUMBER 510 GOTO 310

Well, that's one way. We challenge you to write the program without using IF statements. Then write the program in yet another way, and another, and so on. How many different ways can you invent?

## String Squeezer

Do this one. You will find it useful in future problems. We want a subroutine to squeeze the blanks (spaces) out of a string.

BEFORE SQUEEZING-->AFTER SQUEEZING
THE FORCE IS WITH YOU->THEFORCEISWITHYOU
3 D 6->3D6
NEVER ODD OR EVEN->NEVERODDOREVEN
SOUTH DAKOTA-->SOUTHDAKOTA

Think of your subroutine as a "black box" which accepts a string ZZ\$, squeezes out the spaces, and returns the squeezed string ZZ\$.

ZZ\$ = "A B C" --> STRING SQUEEZER SUBROUTINE --> ZZ\$ = "ABC"

Complete the following program by writing the STRING SQUEEZER SUBROUTINE.

100 REM ** STRING SQUEEZER
110 DIM A\$(50), ZZ\$(50)
120 PRINT CHR\$(125)
200 REM ** GET STRING & SQUEEZE
210 PRINT
220 PRINT "YOUR STRING";: INPUT A\$
230 ZZ\$ = A\$: GOSUB 910
240 PRINT ZZ\$
250 GOTO 210
900 REM ** STRING SQUEEZER SUBROUTINE

Here is a sample RUN of our program.

YOUR STRING? THE FORCE IS WITH YOU
THEFORCEISWITHYOU
3D6
TWO-DIGIT NUMBER SPLITTER
A two-digit number is a whole number in the range 10 to 99, inclusive. A two-digit number has a tens digit and a ones digit.

Write a program to "split" a two-digit number and print the digits separately, line this:

TENS DIGIT = 1
ONES DIGIT = 0
TENS DIGIT = 2
ONES DIGIT = 3
MUST BE A WHOLE NUMBER, 10 TO 99
MUST BE A WHOLE NUMBER, 10 TO 99
MUST BE A WHOLE NUMBER, 10 TO 99
And so on. Accept only whole numbers, 10 to 99.

## The Digit Factory

In the Digit Factory, the raw materials are the numbers 1,2, 3, 4, and 5; the BASIC operations +, -, *, and /; and parentheses ().

The finished products are the decimal digits a, 1, 2,3,4, 5, 6, 7, 8, and 9.

You are the digit maker. For each decimal digit, 0 through 9, write a BASIC expression whose value is equal to the digit. In any such expression:

Use each number (1,2,3,4,5) once and only once.

Use each BASIC operation (+,-,*./) once and only once. No other BASIC operations may be used.

Use as many parentheses as you wish.

For example, here are three BASIC expressions for the digit 5.

2*3/1 + 4 - 5
(3+2-1)*5/4
(3 + 2)/(1*5-4)

Write BASIC expressions for each digit, 0 through 9. Try to write expressions for which one or more of the following is true.

The numbers 1, 2, 3, 4, and 5 appear in increasing order from left to right.

The numbers are in decreasing order (5, 4, 3, 2, 1).

The operations appear in the order +, -, *, / from left to right.

The operations appear in the order /, *, -, + from left to right.

May your factory prosper. Send us some interesting solutions.

## Game Master's Apprentice

Last time, we encouraged you to write a program to roll and display the seven basic characteristics for a character in a fantasy role playing game. Here is our program.

100 REM ** ROLL A CHARACTER
110 PRINT CHR\$(125)
300 REM * ROLL & DISPLAY CHARACTERISTICS
310 GOSUB 910: PRINT "STR", DICE
320 GOSUB 910: PRINT "CON", DICE
330 GOSUB 910: PRINT "SIZ", DICE
340 GOSUB 910: PRINT "INT", DICE
350 GOSUB 910: PRINT "POW", DICE
360 GOSUB 910: PRINT "DEX", DICE
370 GOSUB 910: PRINT "CHA", DICE
500 REM ** TELL HOW TO DO AGAIN
510 PRINT
520 PRINT "TO DO AGAIN, PRESS SPACE BAR"
530 OPEN #1, 4, 0, "K:"
540 GET #1, KEY
550 IF KEY < > ASC(" ") THEN 540
560 CLOSE #1
570 GOTO 110
900 REM ** DICE SUBROUTINE
910 D1 = INT(6*RND(0))
920 D2 = INT(6*RND(0))
930 D3 = INT(6*RND(0))
940 DICE = D1 +D2 + D3
950 RETURN

We entered the program and typed RUN. Here is our first character.

STR 11 This is Bridla. Here name is
CON 12 Gaelic and means "strong friend."
SIZ 10 She is very intelligent (INT 15)
INT 15 and persuasive (CHA 16).
POW 6
DEX 11
CHA 16
TO DO AGAIN, PRESS SPACE BAR

After recording the above information, we pressed the space bar. The computer immediately rolled another character.

STR 10
CON 11 Meet Aloysious Anonymous,
SIZ 10 who is average or near near
INT 12 average in every characteristic.
POW 10
DEX 12
CHA 9
TO DO AGAIN, PRESS SPACE BAR

Aloysious, Bridla, Barostan and Joleen (whom you met last time) are all 16 years old and live in villages near them called Triford in Wundervale. They are characters in a book-in-progress called Adventurer's Handbook: A Beginner's Guide to Role Playing Games.

Our program rolls a number from 3 to 18 for each characteristic. Alas, a character with STR 4, SIZ 13, and DEX 5 will never make it in the GAME MASTER s world.

So, your turn. Replace the DICE SUBROUTINE with any of the following, allowed by a compassionate GM (GAME MASTER). Each of these is a simulation (imitation) of what might happen in an actual game.

Roll 3D6. If DICE is less than 6, assign 6 as the value. The value of DICE will be a number from 6 to 18.

This GM is even more generous. If DICE is less than 6, add 3.

Some GMs allow plays to roll 4D6 and take the best 3D6. That is, if you roll one, three, five, five, you can discard the one and take the other three for a total of 13.

## A Book We Wish We had Written

As perennial beginners, we find the Atari 400/800 BASIC Reference Manual virtually incomprehensible. Fortunately, however, we found a book that, so far, has told us everything we want to know. Here it is:

Your Atari Computer by Lon Poole with Martin McNiff & Steven Cook. Published by Osborne/McGrawHill, 630 Bancroft Way, Berkeley, CA 94710

Thanks, Lon, Martin, and Steve!