Page 1 of 1

syntax error

Posted: Sun Mar 12, 2006 2:32 pm
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

Posted: Sun Mar 12, 2006 3:09 pm
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?

syntax error

Posted: Sun Mar 12, 2006 3:33 pm
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?

Posted: Sun Mar 12, 2006 3:33 pm
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.
*****