// A program to track the scores of four players in a game
// It will be able to list all players and who's winning
// This is a demo for the first use of arrays

// Marc Chee (marc.chee@unsw.edu.au), June 2019

#include <stdio.h>

#define NUM_PLAYERS 4

int main(void) {
    int scores[NUM_PLAYERS] = {0};
    int counter;
    
    // assigning values directly to indexes
    scores[0] = 55;
    scores[1] = 84;
    scores[2] = 32;
    scores[3] = 61;
    
    // assigning scores using user input
    counter = 0;
    while (counter < NUM_PLAYERS) {
        printf("Please enter Player %d's score: ", counter);
        scanf("%d", &scores[counter]);
        counter++;
    }
    
    // loop through and display all scores
    counter = 0;
    while (counter < NUM_PLAYERS) {
        printf("Player %d has scored %d points.\n", counter, scores[counter]);
        counter++;
    }
    
    int highest = 0;
    int indexHighest = -1;
    int lowest = 99999; // what's the issue with this number?
    int indexLowest = -1;
    int total = 0;
    
    counter = 0;
    while (counter < NUM_PLAYERS) {
        if (scores[counter] > highest) {
            highest = scores[counter];
            indexHighest = counter;
        }
        if (scores[counter] < lowest) {
            lowest = scores[counter];
            indexLowest = counter;
        }
        total += scores[counter];
        counter++;
    }
    printf("Player %d has the highest score of %d.\n", indexHighest, highest);
    printf("Player %d has the lowest score of %d.\n", indexLowest, lowest);
    printf("Total points scored across the players is %d", total);
    
    return 0;
}
