You are here:

# Qbasic, Quickbasic/I'm getting errors and need help

Question
I missed class last week and am totally lost on this homework problem, I need your help asap. The program is due tonight by midnight. I will provide what I got so far, but it's not much and it's definitely not right.

Here is the question:
Piecework workers are paid by the piece. Often, workers who produce a greater quantity of output are paid at a higher rate.

1-199 pieces completed   \$.50 each
200-399          \$.55 each
400-599          \$.60 each
600 or more          \$.65 each

INPUT: For each worker, input the name and number of pieces completed. Data may be entered with READ or INPUT statements.

OUTPUT: Print an appropriate title and column headings. There should be on detail line for each worker, which shows the name, the number of pieces and the dollar amount earned.

PROCESSING: For each person, compute the pay earned by multiplying the number of pieces by the appropriate price. Accumulate the total number of pieces and the total dollar amount paid.

SAMPLE PROGRAM OUTPUT:

PIECEWORK WEEKLY REPORT
NAME          PIECES      PAY

JOHNNY BEGOOD          265         145.75
SALLY GREAT          650         422.50
SAM KLUTZ          177         88.50
PETE PRECISE          400         240.00
FANNIE FANTASTIC        399         219.45
MORRIE MELLOW          200         110.00

TOTALS          2091        1226.20

MY CODE: (SO FAR..) There are some parts I honestly do not have a clue. I have missed a lot of classes due to unfortunate circumstances. If you could help at all, it would be greatly appreciated.

CLS

GOSUB intializevariables
GOSUB processdetail
GOSUB processes
GOSUB printtotals

END

initializevariables:
LET T\$ = "NAME   PIECE   PAY"
LET D\$ = "\name\ ### ####.##
RETURN

LPRINT
LPRINT
RETURN

processdetail:
DO UNTIL UCASE\$(nam\$) = "END"
GOSUB processes
GOSUB printtotals
LOOP
RETURN

DATA Johnny Begood, 265, 145.75
DATA Sally Great, 650, 422.50
DATA Sam Klutz, 177, 88.50
DATA Pete Precise, 400, 240.00
DATA Fannie Fantastic, 399, 219.45
DATA Morrie Mellow, 200, 110.00
DATA end, 0, 0
RETURN

processes:
IF piece < 200 THEN
LET Pay = Piece * .5
END IF

printtotals:
PRINT name\$
PRINT Piece
PRINT Pay
RETURN

Hi Chris,

I see three immediate problems.  First, in your DATA statements, every string needs to be in quotes, so your statements should look like this:

```DATA "Johnny Begood", 265, 145.75
DATA "Sally Great", 650, 422.50
DATA "Sam Klutz", 177, 88.50
DATA "Pete Precise", 400, 240.00
DATA "Fannie Fantastic", 399, 219.45
DATA "Morrie Mellow", 200, 110.00
DATA "end", 0, 0```

To tag along with this, you should only need two fields, name, and number of pieces made, since we'll be calculating how much money they have made.

Second, your print statements in printtotals: are a little off.  For instance, you are READing in nam\$, but trying to print name\$.  Always make sure you are using the proper variable names, so as a correction, it should be:
`PRINT nam\$`

`READ name\$, Piece, Pay`

Since I mentioned that you should get rid of the Pay field in your data statements, your read should look lik this:
`READ name\$, Piece`

Also, you need to separate your printing variables with commas to tabulate your information, so to make name\$, Piece, and Pay print all on the same line with some spacing in between them:
`PRINT name\$, Piece, Pay`

Third, your processes: subroutine isn't checking all the cases for different amounts of money.

```1-199 pieces completed   \$.50 each
200-399          \$.55 each
400-599          \$.60 each
600 or more          \$.65 each```

To do ranges with IF statements, outside of making functions, there is no easy way to have QBasic magically do this, so it will take some typing:

```IF (Piece >= 1) AND (Piece < 200) THEN
LET Pay = Piece * 0.5
ELSEIF (Piece >= 200) AND (Piece < 400) THEN
LET Pay = PIece * 0.55
ELSEIF ... '' You do the rest
'' ...
END IF```

That should set you off in the right direction.

Take care,
-Alex
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thank You! This has pointed me in the right direction. Got it working.

Qbasic, Quickbasic

Volunteer

#### Alex Barry

##### Expertise

I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

##### Experience

I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future. Currently, I am only active on the QB64.net forums, but I appear on occasion on FreeBASIC.net's forums as well.

Education/Credentials
Highschool - 2007