// aug6ex1.cpp : Defines the entry point for the console application.
// This program reads in an employee ID and a salary for N employees

#include "stdafx.h"
#define maxemp 100

int main(int argc, char* argv[])
{    int emp_id [maxemp];
     float salary [maxemp];

	 int actual_num, which_emp, pos, hold_id, left, right;
	 float max_salary= -999.99, hold_salary;


	 printf("Please type num of employees:  ");
	 scanf("%d", &actual_num);

	 if (actual_num > maxemp) {
		 printf("Nooooo!  Too many - recompile with more room!!!\n");
	 } /* end if actual_num */
	 else {

     for (which_emp=0; which_emp < actual_num; which_emp++) {

         scanf("%d %f", &emp_id[which_emp], &salary[which_emp]);

		 if (salary[which_emp] > max_salary)
			 max_salary = salary[which_emp];


	 }  /* end for which_emp */


     printf("Biggest salary of $ %6.2f belongs to employee(s) ", max_salary);

	 for (pos=0; pos < actual_num; pos++) 
		 if (salary[pos] == max_salary )
			 printf("%d ", emp_id[pos]);

	 printf("\n\n");


// now, sort them in descending order by salary


        for (left=0; left < actual_num -1; left++)
			for (right=left+1; right < actual_num; right++)
				if (salary[left] < salary[right])  {

                       hold_salary = salary[left];
					   salary[left] = salary[right];
					   salary[right] = hold_salary;

					   hold_id = emp_id[left];
					   emp_id[left] = emp_id[right];
					   emp_id[right]=hold_id;

				} /* end if salary */


      printf("Here are the salaries in desceding order:\n");

	  for (pos=0; pos < actual_num; pos++)
		  printf("%d %6.2f \n", emp_id[pos], salary[pos]);

	 }  /* end else actual_num */

	return 0;
}