0

Would love some help with a dilemma I am facing right now. I need to take the name, their sales figure and calculate if they're entitled to a bonus and how much. I am fine with doing all of this!

THIS IS PSEUDO-CODE:

read sales_rep
read sales_total

if $sales_total -gt 1000000
then
    echo '$sales_rep has a £1,500 bonus this quarter
    bonus = $1500

elif $sales_total -gt 100000 || $sales_total -lt 999999
then
    echo '$sales_rep has a £750 bonus this quarter
    bonus = £750

else
    echo '$sales_rep has no bonus this quarter'
    bonus = £0

It is the second part of the problem I need help with. I need to organise the sales_person in order of quarter sales. I was going to simply dump them in an array and display. But I have not idea how to organise this and keep the data together.

Any help would be hugely appreciated. Any questions, please ask! I may not have been clear!

Thanks!

samjuel
  • 3
  • 3
  • 1
    So you want to sort an array? What have you tried? Do any of the answers on this question help? http://stackoverflow.com/q/7442417/2088135 – Tom Fenech Mar 23 '16 at 19:41
  • For example: the first input user is Fred who has sold £1000000 and he get's a bonus of £1500. The second input is Sophie who has sold £500000, she get's a £750 Bonus. I need it to be sorted like: Fred £1000000 £1500 Sophie £500000 £750 – samjuel Mar 23 '16 at 19:50

1 Answers1

0

You could output the user,sales,bonus values as delimited strings (say, with spaces, unless you're using full names, in which case try commas), and pipe the result to sort -rn -k2.

So if you generate output of

Alice,$964375,$750
Bob,$87234,$0
Carol,$1360263,$1500

and you then pipe that to sort -rn -k2 -t, , you will get:

Carol,$1360263,$1500
Alice,$964375,$750
Bob,$87234,$0
Keith Tyler
  • 719
  • 4
  • 18