I need a properly spaced Multiplication Table using For,Next loops that I can easily whip up on my QBasic. It needs to use If/Then/Elses for the spacing issue. Multiplication table of 10x10. It needs to be able to evenly space between single digit, double digit, and triple digit numbers.

I have somewhat the body for it, but I can't figure out the spacing.

Typing from memory here...

CLS

FOR J = 1 TO 10

FOR I = 1 TO 10

IF X * Y < 10 THEN

PRINT X * Y; " "; (<-- 2 spaces)

END IF

IF X * Y > 10 AND X * Y < 100 THEN

PRINT X * Y; " "; (<-- 1 space)

END IF

ELSE

PRINT X * Y;

END IF

NEXT I

NEXT J

ENDPlease tell me how to correctly code this, and how to fix the spacing issue!!!

If you could type what your program looked like with the For,Next and If/Then/Elses, that would be greatly appreciated.

Doesn't count indentations on the loops, but they are there!!!

The simplest "tried and true" method is to add a bunch of spaces (to left, for right-just, to right for left-justified) after converting the number to a string.

Here is a generic Basic program (qb, vb, or gw)'=== begin BASIC program FOR I = 1 TO 10 FOR J = 1 TO 10 PRINT RIGHT$(" " + STR$(J * I), 4); NEXT J PRINT NEXT I '===== end basic code

If (pun intended!) you really want to use IF statements, then this might do:

FOR J=1 TO 10

SP$=""

IF I*J<100 THEN SP$=" "

IF I*J<10 THEN SP$=" "

PRINT SP$;I*J;

...

Ask Your Question

Weekly Poll

When do you think most people will be driving electric cars?

Discuss in The Lounge

Poll History