The pay of an hourly worker is calculated by multiplying the hours worked by the hourly rate—up to 40 hours;

LANGUAGE:  C++

CHALLENGE:

The pay of an hourly worker is calculated by multiplying the hours worked by the hourly rate—up to 40 hours;
any hours worked beyond 40 are paid at time-and-a-half (one and a half times the hourly rate).
Given the variables hours, rate, and pay have already been declared and assigned values, write a fragment of code (one or more statements) that assigns to pay the proper value, taking into account time-and-a-half.
(basic arithmetic, basic conditional)

SOLUTION:


pay = ((hours > 40)?(40*rate + (hours-40)*1.5*rate):(hours*rate));