need help on a program

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
need help on a program

Post by Guest » Sun Jul 20, 2003 10:21 pm

I'm having a litte problem with my program, here's the code I'm using... I'm somewhat of a beginner, I'm not that professional, I don't care if people think I should go about this differently. My problem is that when I try to run this, my QB compiler highlights DUMMYHP and has an error message that says "duplicate label!" could someone explain what this problem is, why it's there and how to fix it?

1 CLS
2 RESTORE
3 COLOR 0, 0
4 PRINT "."
PRINT "."
PRINT "."      'THESE ARE FOR TAKING UP PUTING THE TEXT BELOW LOWER ON THE SCREEN
PRINT "."
PRINT "."
COLOR 15, 0
10 PRINT "   WELCOME TO BOXING TRAINING"
PRINT ""
20 PRINT "   PRESS SELECT BUTTONS TO FIGHT THE BALOON DUMMY"
PRINT ""
30 PRINT "   PRESS RETURN"
35 SLEEP
PRINT ""
40 PRINT "   'L' FOR LEFTHOOK, 'R' FOR RIGHT HOOK, 'U' FOR UPPERCUT,"
PRINT ""
50 PRINT "   AND 'S' FOR A KNUCKLE SANDWHICH"
55 SLEEP
PRINT ""
60 PRINT "   EACH DOES A CONSTANTLY RANDOM NUMBER OF DAMAGE"
PRINT ""
70 PRINT "   PRESS Q TWICE TO QUIT"
75 SLEEP
PRINT ""
80 PRINT "   THE DUMMY HAS LOTS OF DURABILITY, SO IT MIGHT TAKE A WHILE,"
PRINT ""
90 PRINT "   KEEP ON TRYING"
PRINT ""
100 PRINT "                                     READY???"
SLEEP
PRINT ""
110 PRINT "                                       GO!!!"


490 LET DUMMYHP = 800
500 DO
520 PRINT
530 BUTTON$ = INKEY$
540 SELECT CASE BUTTON$

550 CASE L
 DAMAGE = INT(RND * 40) + 20
  IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
&nbsp; PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"


560 CASE R
&nbsp;DAMAGE = INT(RND * 25) + 30
&nbsp; IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
&nbsp; PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"


570 CASE U
&nbsp;DAMAGE = INT(RND * 10) + 40
&nbsp; IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
&nbsp; PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"


580 CASE S
&nbsp;DAMAGE = INT(RND * 70) + 1
&nbsp; IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
&nbsp;DUMMYHP -DAMAGE
&nbsp; PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"



590 END SELECT

IF DUMMYHP <= 1 THEN GOTO 710

700 LOOP UNTIL (UCASE$(BUTTON$) = "Q")
705 GOTO 720
710 PRINT "YOU WON!!!!!!!"
720 END

Guest

Re: need help on a program

Post by Guest » Mon Jul 21, 2003 3:32 pm

Well you got three identical lines DUMMYHP -DAMAGE and I think they should read DUMMYHP=DUMMYHP-DAMAGE. The version of QB you are using can accept labels instead of line numbers and thinks you are duplicating label DUMMYHP.
Good luck

Guest

Re: need help on a program

Post by Guest » Mon Jul 21, 2003 3:41 pm

BTW I know you said you don't care but just try using LOCATE to position text on the screen. eg. LOCATE 10,20 :print "YOUR MESSAGE" will show "YOUR MESSAGE" on line 10 starting at position 20. It saves a lot of print "." statements.
I hope you have as much fun with QBasic as I have had.

Guest

Re: need help on a program

Post by Guest » Fri Jul 25, 2003 4:17 pm

What Vagrant said about line lables is correct.

I also attempted to test run your code...you will ALSO be getting a problem with 'line lables not allow between select/case clauses'. simply remove the line numbers between select/end select.

Also, the RESTORE is not necessary in the very beginning of the program. &nbsp;You'll only need to use it when you need to tell the program to use a certain DATA section again.

Here's some of the corrected coded:
1 &nbsp; CLS
&nbsp; &nbsp;LOCATE 6, 1
&nbsp; &nbsp;COLOR 15, 0
10 &nbsp;PRINT " &nbsp; WELCOME TO BOXING TRAINING"
&nbsp; &nbsp;PRINT ""
20 &nbsp;PRINT " &nbsp; PRESS SELECT BUTTONS TO FIGHT THE BALOON DUMMY"
&nbsp; &nbsp;PRINT ""
30 &nbsp;PRINT " &nbsp; PRESS RETURN"
35 &nbsp;SLEEP
&nbsp; &nbsp;PRINT ""
40 &nbsp;PRINT " &nbsp; 'L' FOR LEFTHOOK, 'R' FOR RIGHT HOOK, 'U' FOR UPPERCUT,"
&nbsp; &nbsp;PRINT ""
50 &nbsp;PRINT " &nbsp; AND 'S' FOR A KNUCKLE SANDWHICH"
55 &nbsp;SLEEP
&nbsp; &nbsp;PRINT ""
60 &nbsp;PRINT " &nbsp; EACH DOES A CONSTANTLY RANDOM NUMBER OF DAMAGE"
&nbsp; &nbsp;PRINT ""
70 &nbsp;PRINT " &nbsp; PRESS Q TWICE TO QUIT"
75 &nbsp;SLEEP
&nbsp; &nbsp;PRINT ""
80 &nbsp;PRINT " &nbsp; THE DUMMY HAS LOTS OF DURABILITY, SO IT MIGHT TAKE A WHILE,"
&nbsp; &nbsp;PRINT ""
90 &nbsp;PRINT " &nbsp; KEEP ON TRYING"
&nbsp; &nbsp;PRINT ""
100 PRINT " &nbsp; &nbsp; &nbsp; READY ? ? ?"
&nbsp; &nbsp;SLEEP
&nbsp; &nbsp;PRINT ""
110 PRINT " &nbsp; &nbsp; &nbsp; &nbsp; GO!!!"
490 LET DummyHP = 800
500 DO
520 &nbsp; &nbsp; PRINT
530 &nbsp; &nbsp; BUTTON$ = INKEY$
540 &nbsp; &nbsp; SELECT CASE BUTTON$
&nbsp; &nbsp; &nbsp; &nbsp;CASE IS = "L"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAMAGE = INT(RND * 40) + 20
&nbsp; &nbsp; &nbsp; &nbsp;CASE IS = "R"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAMAGE = INT(RND * 25) + 30
&nbsp; &nbsp; &nbsp; &nbsp;CASE IS = "U"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAMAGE = INT(RND * 10) + 40
&nbsp; &nbsp; &nbsp; &nbsp;CASE IS = "S"
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DAMAGE = INT(RND * 70) + 1
&nbsp; &nbsp; &nbsp; &nbsp;END SELECT
&nbsp; &nbsp; &nbsp; &nbsp;IF DummyHP <= 1 THEN GOTO 710
&nbsp; &nbsp; &nbsp; &nbsp;IF DAMAGE >= 50 THEN
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PRINT "KAPOW!!!"
&nbsp; &nbsp; &nbsp; &nbsp;ELSEIF DAMAGE <= 30 AND Damage <= 49 THEN
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PRINT "BOP!"
&nbsp; &nbsp; &nbsp; &nbsp;ELSE
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PRINT "WHAM!!"
&nbsp; &nbsp; &nbsp; &nbsp;ENDIF
&nbsp; &nbsp; &nbsp; &nbsp;DummyHP = DummyHP - Damage
&nbsp; &nbsp; &nbsp; &nbsp;LOCATE 20, 1: PRINT STRING$(50, " ")
&nbsp; &nbsp; &nbsp; &nbsp;LOCATE 20, 1: PRINT "DUMMY CURRENTLY HAS "; DummyHP; " HP LEFT"
700 LOOP UNTIL (UCASE$(BUTTON$) = "Q")
705 GOTO 720
710 PRINT "YOU WON!!!!!!!"
720 END
Enjoy!

Post Reply