10-24-2003, 05:55 PM
i have to make a program that will print out a multiplication table and allow the user to input 2 numbers from 2-10 for that table
i need help making the numbers go over...
i need help making the numbers go over...
Quote:i have to make a program that will print out a multiplication table and allow the user to input 2 numbers from 2-10 for that table
i need help making the numbers go over...
CLS
' Print mult table
FOR a = 1 TO 10
FOR b = 1 TO 10
PRINT USING "####"; a * b;
NEXT b
PRINT
NEXT a
PRINT
PRINT
PRINT
' get 2 numbers and multiply them
redo:
INPUT "input first value (2 to 10) ", x
IF (x > 10) OR (x < 2) THEN
PRINT "number out of range..try again"
GOTO redo
END IF
INPUT "input second value (2 to 10) ", y
IF (y > 10) OR (y < 2) THEN
PRINT "number out of range..try again"
GOTO redo
END IF
PRINT x; "x"; y; "="; x * y
END
INPUT "Please enter a number: ", a%
IF a% > 1 AND a% < 11 THEN
PRINT "Table for number" + STR$(a%)
FOR i% = 1 TO 10
PRINT STR$(a%) + "x" + LTRIM$(STR$(i%)) + " =" + STR$(a% * i%)
NEXT i%
ELSE
PRINT "Invalid entry!"
END IF
Quote:Simple: This is more compact =)
Mango, its bad to use 'GOTO' =*(
CLS
FOR a = 1 TO 30
FOR b = 1 TO 30
FOR c = 1 TO 30
IF a + b + c > 75 THEN GOTO outtahere
NEXT c
NEXT b
NEXT a
outtahere:
PRINT a, b, c
CLS
ExcuseMeIHaveToBeGoingNow = 0
FOR a = 1 TO 30
FOR b = 1 TO 30
FOR c = 1 TO 30
IF a + b + c > 75 THEN ExcuseMeIHaveToBeGoingNow = 1
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT c
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT b
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT a
PRINT a, b, c
CLS
DO
FOR a = 1 to 30
FOR b = 1 to 30
FOR c = 1 to 30
IF a + b + c > 75 THEN EXIT DO
NEXT c, b, a
LOOP UNTIL 1
PRINT a, b, c
Quote:TheBigBasicQ Wrote:Simple: This is more compact =)
Mango, its bad to use 'GOTO' =*(
???????Which of these is "better"????????
the bad code with the dreaded goto (pick me, pick me :bounce: :bounce: :bounce: )
Code:CLS
FOR a = 1 TO 30
FOR b = 1 TO 30
FOR c = 1 TO 30
IF a + b + c > 75 THEN GOTO outtahere
NEXT c
NEXT b
NEXT a
outtahere:
PRINT a, b, c
........OR......
the good code that properly exits each loop (all I can say is Ralph... :barf: :barf: :barf: )
Code:CLS
ExcuseMeIHaveToBeGoingNow = 0
FOR a = 1 TO 30
FOR b = 1 TO 30
FOR c = 1 TO 30
IF a + b + c > 75 THEN ExcuseMeIHaveToBeGoingNow = 1
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT c
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT b
IF ExcuseMeIHaveToBeGoingNow THEN EXIT FOR
NEXT a
PRINT a, b, c
With nested loops, goto is handy for exiting the nest before the angry mother bird returns :king:
Do
Input "Enter a no. between 2 to 10 : ", a%
if a% > 1 and a% < 11 then exit do else print "Sorry! Try again"
Loop