syntax error

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
flirt85
Coder
Posts: 13
Joined: Sun Mar 12, 2006 2:14 pm

syntax error

Post by flirt85 »

:?: Thanks for your help! The program is running now, with one minor problem. In the output screen, one of the Datas is listed twice-

Stella Star 15.95 45 121.22 636.40

Stella Star 15.95 45 121.22 0

How do I correct this? I only need the top entry for Stella.



CLS
DIM emp AS STRING
DIM wage AS SINGLE
DIM hours AS SINGLE
DIM pay AS SINGLE
DIM irs AS SINGLE
DIM tpay AS SINGLE
DIM x AS INTEGER 'variable assignments

PRINT "Name Wage Hours IRS Total Pay" 'headings
PRINT "------ ------ ------ ----- ----------"

DATA "Tom Jones",12.88,45,"Mary Bell",15.96,38 'emp name, wage, and hours (there are six more entries in data)

FOR x = 1 TO 8 'read numbers from eight data entries
READ emp, wage, hours
IF hours <= 40 THEN 'set if first loop
pay = wage * hours 'set first pay rate
ELSE
pay = 40 * wage + 1.5 * wage * (hours - 40)
END IF
irs = ((pay * .16) * 100 \ 1) / 100 'sets IRS amount
tpay = (tpay * 100 \ 1) / 100

PRINT
PRINT emp, wage, hours, irs, total
Last edited by flirt85 on Sun Mar 12, 2006 5:36 pm, edited 2 times in total.
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

if this is the exact code you have and assuming your data statements have no errors in them, the only errir that strikes me is your READ statement

it reads: READ Emp, Wage Hour

it should be: READ Emp, Wage, Hour

see where your missing comma is?
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
flirt85
Coder
Posts: 13
Joined: Sun Mar 12, 2006 2:14 pm

syntax error

Post by flirt85 »

I just checked my actual code in Qbasic, and I do have the comma separating each of the variables after READ.....any other ideas?
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Don't put more than one employee's stuff on the same DATA statement. It just tends to confuse you.

Code: Select all

DATA "Tom Jones",12.88,45,"Mary Bell",15.96,38 'emp name, wage, and hours (there are six more entries in data)
Instead, do this:

Code: Select all

DATA "Tom Jones",12.88,45
DATA "Mary Bell",15.96,38 
and so on, one DATA statement for each employee.
Then you can count how many DATA statements you have and use this count in the FOR statement.
Also, you can clearly see that each READ statement which corresponds to each DATA statement, needs to have 3 variables: emp, wage, and hours. THERE IS NO DATA FOR THE "PAY", you have to compute this.
*****
Post Reply