//===================================================== file = maxmin.c =====
//=  Program to implement max-main scheduling                               =
//===========================================================================
//=  Notes: 1) Takes input from console and writes output to console        =
//=         2) Limited to MAX users (set in #define)                        =
//=         3) Users must be entered in order (lowest to highest) by        =
//=            by demand                                                    =
//=-------------------------------------------------------------------------=
//= Example execution:                                                      =
//=                                                                         =
//=   ----------------------------------------- maxmin.c -----              =
//=   -        Program to implement maxmin scheduling        -              =
//=   --------------------------------------------------------              =
//=   Capacity ========================================> 10.0               =
//=   Number of users =================================> 4                  =
//=   User demand from lowest to highest for 4 users...                     =
//=     Demand for user # 0 =================> 1.0                          =
//=     Demand for user # 1 =================> 3.0                          =
//=     Demand for user # 2 =================> 6.0                          =
//=     Demand for user # 3 =================> 7.0                          =
//=   --------------------------------------------------------              =
//=   Allocated capacity is:                                                =
//=     User # 0 = 1.000000                                                 =
//=     User # 1 = 3.000000                                                 =
//=     User # 2 = 3.000000                                                 =
//=     User # 3 = 3.000000                                                 =
//=   --------------------------------------------------------              =
//=-------------------------------------------------------------------------=
//=  Build: bcc32 maxmin.c                                                  =
//=-------------------------------------------------------------------------=
//=  Execute: maxmin                                                        =
//=-------------------------------------------------------------------------=
//=  Author:                                                                =
//=-------------------------------------------------------------------------=
//=  History: KJC (10/07/10) - Genesis of maxmin_template.c                 =
//===========================================================================
//----- Include files -------------------------------------------------------
#include <stdio.h>            // Needed for printf()
#include <stdlib.h>           // Needed for ato*()
#include <assert.h>           // Needed for assert()

//----- Defines -------------------------------------------------------------
#define MAX      10           // Maximum number of users

//===== Main program ========================================================
void main(void)
{
  char   inString[256];       // Input string
  double capacity;            // Capacity of system
  int    numUser;             // Number of users
  double demand[MAX];         // User demand
  double allocate[MAX];       // User allocations
  // *** insert other variables as needed here ***
  int    i;                   // Loop counter

  // Output banner
  printf("----------------------------------------- maxmin.c ----- \n");
  printf("-        Program to implement maxmin scheduling        - \n");
  printf("-------------------------------------------------------- \n");

  // Prompt for capacity
  printf("Capacity ========================================> ");
  scanf("%s", inString);
  capacity = atof(inString);

  // Prompt for number of users
  printf("Number of users =================================> ");
  scanf("%s", inString);
  numUser = atoi(inString);
  assert(numUser <= MAX);

  // Prompt for demand for each user
  printf("User demand from lowest to highest for %d users... \n", numUser);
  for (i=0; i<numUser; i++)
  {
    printf("  Demand for user #%2d =================> ", i);
    scanf("%s", inString);
    demand[i] = atof(inString);
  }

  // Clear allocate vector
  for (i=0; i<numUser; i++)
    allocate[i] = 0.0;

  // Main scheduling loop

  // *** Insert max-min scheduling code here ***

  // Output allocations
  printf("-------------------------------------------------------- \n");
  printf("Allocated capacity is: \n");
  for (i=0; i<numUser; i++)
    printf("  User #%2d = %f \n", i, allocate[i]);
  printf("-------------------------------------------------------- \n");
}

