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
PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"
560 CASE R
DAMAGE = INT(RND * 25) + 30
IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"
570 CASE U
DAMAGE = INT(RND * 10) + 40
IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
PRINT "DUMMY CURRENTLY HAS "; DUMMYHP; " HP LEFT"
580 CASE S
DAMAGE = INT(RND * 70) + 1
IF DAMAGE >= 50 THEN PRINT "KAPOW!!!"
IF DAMAGE <= 30 THEN PRINT "BOP!"
IF DAMAGE >= 29 AND DAMAGE <= 51 THEN PRINT "WHAM!!"
DUMMYHP -DAMAGE
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
need help on a program
Moderators:Administrator, Global Moderator
Re: need help on a program
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
Good luck
Re: need help on a program
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.
I hope you have as much fun with QBasic as I have had.
Re: need help on a program
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. 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:
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. 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:
Enjoy!1 CLS
LOCATE 6, 1
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$
CASE IS = "L"
DAMAGE = INT(RND * 40) + 20
CASE IS = "R"
DAMAGE = INT(RND * 25) + 30
CASE IS = "U"
DAMAGE = INT(RND * 10) + 40
CASE IS = "S"
DAMAGE = INT(RND * 70) + 1
END SELECT
IF DummyHP <= 1 THEN GOTO 710
IF DAMAGE >= 50 THEN
PRINT "KAPOW!!!"
ELSEIF DAMAGE <= 30 AND Damage <= 49 THEN
PRINT "BOP!"
ELSE
PRINT "WHAM!!"
ENDIF
DummyHP = DummyHP - Damage
LOCATE 20, 1: PRINT STRING$(50, " ")
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