Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some help with a simple program... Calculating overtime pay...
#1
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
Reply
#2
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.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
Thanks Ralph!
Reply
#4
Happy to have been of some help!  Smile  Keep using QB for other things.  It's always a nice challenge.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
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
  READ U1$(i), H1(i),P1(i)
NEXT i

That would read all the values into the variables.
I would code the following parts in a similar manner.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)