You are here:

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


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.


      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.


GOSUB intializevariables
GOSUB writeheading
GOSUB processdetail
GOSUB processes
GOSUB printtotals


LET D$ = "\name\ ### ####.##


GOSUB readdata
GOSUB processes
GOSUB printtotals
GOSUB readdata

READ nam$, Piece, Pay
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

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

PRINT name$

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$

OR you could change your READ statement to:
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.

We already have this information:
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
'' ...

That should set you off in the right direction.

Take care,

Qbasic, Quickbasic

All Answers

Ask Experts


Alex Barry


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.


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 forums, but I appear on occasion on's forums as well.

Highschool - 2007

©2017 All rights reserved.