Qbasicnews.com
June 21, 2021, 03:34:16 AM
 Pages: [1]
 Author Topic: Some help with a simple program... Calculating overtime pay...  (Read 4430 times)
Temperence
New Member

Posts: 2

 « on: May 10, 2008, 09:29:51 PM »

Trying to write a simple script to calculate overtime pay for four individuals. Overtime starts after 40 hours, and is 1.5 normal wage.

It's telling me "Type mismatch error on line 4."

Quote
DATA Alley Oop, 40, 6.25, Jack Daniels, 48, 6, Johnny Walker, 40, 6.50, Last One, 0, 0
READ U1, H1, P1, U2, H2, P2, U3, H3, P3, U4, H4, P4

IF H1>40 THEN
LET T1 = P1 * 40
T1 = T1 + ((P1*1.5) * (H1-40))
ENDIF

IF H2>40 THEN
LET T2 = P2 * 40
T2 = T2 + ((P2*1.5) * (H2-40))
ENDIF

IF H3>40 THEN
LET T3 = P3 * 40
T3 = T3 + ((P3*1.5) * (H3-40))
ENDIF

IF H4>40 THEN
LET T4 = P4 * 40
T4 = T4 + ((P4*1.5) * (H4-40))
ENDIF

PRINT T1
PRINT T2
PRINT T3
PRINT T4
 Logged
Ralph
Ancient Guru

Posts: 544

 « Reply #1 on: May 11, 2008, 01:30:02 AM »

I found two problems:

1. The variables U must be strings, so, they must be used as U1\$, U2\$, U3\$, and U4\$ throughout

2. You must include the case where the hours worked are NOT larger then 40.  I did it by changing your code thus, where I show the change for the first values:
IF H1 > 40 THEN
LET T1 = P1 * 40
T1 = T1 + P1 * 1.5 * (H1 - 40) 'the other parenthesis are not required
ELSE
T1 = P1 * H1
END IF

Just change the following three cases accordingly.
 « Last Edit: May 12, 2008, 12:18:04 AM by Ralph » Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Temperence
New Member

Posts: 2

 « Reply #2 on: May 11, 2008, 12:42:10 PM »

Thanks Ralph!
 Logged
Ralph
Ancient Guru

Posts: 544

 « Reply #3 on: May 11, 2008, 01:12:33 PM »

Happy to have been of some help!     Keep using QB for other things.  It's always a nice challenge.
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Ralph
Ancient Guru

Posts: 544

 « Reply #4 on: May 12, 2008, 12:22:32 AM »

By the way, I would have coded your program using arrays, such as:
U1\$(4), H1(4), P1(4)

Then, to read, you could use:
FOR i = 1 to 4