Qbasicnews.com

Full Version: multiplication tabel
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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...
"making the numbers go over"... I dont understand what you mean by this. Are you just having problems printing the table out?
i dont understand what you mean by that also... could you post the code?
erm oracle were are you. need you to tell us what this message means.
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...

I don't usually do homework for people, but...well...maybe this will get you started as a great programmer.

Code:
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
Simple: This is more compact =)

Code:
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

Mango, its bad to use 'GOTO' =*(
Quote: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:
Code:
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

*peace*

Meg.
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:

Mango, Goto is a taboo in the programming community.

Why? (you ask)

Ever heard of "Out Of Stack Space" errors?

Also, the same result can be obtained by *not* using goto in a cleaner manner:

Code:
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
yes, i agree. also, don't go around telling new people that goto is satan, It gets the job done. later on they will move on to bigger and better things.
Pages: 1 2 3