If you're looking to implement a simple procedural update of employees, you haven't specified a language (which is good since I only provide pseudo-code for homework anyway), but here it is:
def update (N,MAX)
if N < 1:
return
for every employee E:
select E.catagory:
if 'C':
E.salary = E.salary * (1 + N / 100)
endif
if 'B':
E.salary = E.salary * (1 + 2 * N / 100)
endif
if 'A':
E.salary = E.salary * (1 + 3 * N / 100)
endif
endselect
if E.salary > MAX:
E.salary = MAX
endif
print E.name " is now on a wage of $" E.salary
endfor
enddef
Now your task is to translate that into whatever language you have to implement this in :-)
If you're wanting to solve all the unknowns in an equation, you have a problem (conflicting requirements). It appears you may be after the value of N which will make the largest wage $50K.
You just need to go through every employee and figure the maximum percentage out:
def update (MAX) returns N:
N = Infinity
for every employee E:
select E.catagory:
if 'C':
ThisN = MAX / E.salary - 1
endif
if 'B':
ThisN = (MAX / E.salary - 1) / 2
endif
if 'A':
ThisN = (MAX / E.salary - 1) / 3
endif
endselect
if ThisN < N:
N = ThisN
endif
endfor
if N < 1:
# Conflicting requirement
endif
enddef
It's possible to come up with a value of N
that's less than 1 if, for example, a category C employee is already on $50K. You need to decide what you want to do in that case, either:
- give no-one a payrise (violates the >=1% rule).
- give everyone 1% (violates the $50K cap rule).
- give everyone 1% but cap at $50K (violates the 1,2,3 multiplier rule).
Once you have the percent increase from that code (with your decision on what to do for the conflicting requirements), you can pass it into the first piece of code above to actually do and print the update.