215k views
4 votes
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)

User Krupal
by
8.3k points

1 Answer

5 votes
C# program code;

if (hours <=40)
{
pay = rate * hours;
}
else
{
extra_hours = hours - 40;
pay = 40*rate + extra_hours *rate*1,5;
}
User MCB
by
7.2k points