05-11-2004, 09:18 AM
I'll just give you some quick style pointers:
* You don't need line numbers. Get rid of them, they make your code look ugly
* Also, you can comment your code with an apostrophe (') instead of REM
* If you do remove the line numbers your gotos will crash. Just replace them with a label for starters, until you learn about loops and how to completely avoid GOTO.
So your program above becomes this:
[syntax="qbasic"]' Program to calcuate Employees hours and pay
CLS
PRINT " NAME ", "HOURS ", "PAY"
PRINT
' employees name, hours worked, pay rate
DATA Alley Oop, 40, 6.25
DATA Jack Daniels, 48, 6
DATA Johnny Walker, 40, 6.50
DATA last one, 0, 0
' E$=employee name hr=hours worked pay=payrate
nextemp:
READ e$, hr, pay
IF pay = 0 THEN GOTO 180
' ot=overtime pay, othr=overtime hours
ot = pay * 1.5
othr = hr - 40
' grpay=gross pay
IF hr > 40 THEN grpay = 40 * pay + othr * ot
IF hr < 41 THEN grpay = hr * pay
PRINT USING "& ## $###.##"; e$; hr; grpay
' topay= total pay
topay = grpay + grpay + grpay
GOTO nextemp
PRINT
PRINT USING "Total pay is $###.##"; topay
END [/syntax]
(if you want to post highlighted code, put it in [syntax="qbasic"][/syntax] tags)
Anyway, you need to change this line:
topay = grpay + grpay + grpay
See if you can work it out!
* You don't need line numbers. Get rid of them, they make your code look ugly
* Also, you can comment your code with an apostrophe (') instead of REM
* If you do remove the line numbers your gotos will crash. Just replace them with a label for starters, until you learn about loops and how to completely avoid GOTO.
So your program above becomes this:
[syntax="qbasic"]' Program to calcuate Employees hours and pay
CLS
PRINT " NAME ", "HOURS ", "PAY"
' employees name, hours worked, pay rate
DATA Alley Oop, 40, 6.25
DATA Jack Daniels, 48, 6
DATA Johnny Walker, 40, 6.50
DATA last one, 0, 0
' E$=employee name hr=hours worked pay=payrate
nextemp:
READ e$, hr, pay
IF pay = 0 THEN GOTO 180
' ot=overtime pay, othr=overtime hours
ot = pay * 1.5
othr = hr - 40
' grpay=gross pay
IF hr > 40 THEN grpay = 40 * pay + othr * ot
IF hr < 41 THEN grpay = hr * pay
PRINT USING "& ## $###.##"; e$; hr; grpay
' topay= total pay
topay = grpay + grpay + grpay
GOTO nextemp
PRINT USING "Total pay is $###.##"; topay
END [/syntax]
(if you want to post highlighted code, put it in [syntax="qbasic"][/syntax] tags)
Anyway, you need to change this line:
topay = grpay + grpay + grpay
See if you can work it out!