// TODO: Implement populate_array
/*
 * Convert a 9 digit int to a 9 element int array.
 */
int populate_array(int sin, int *sin_array) {
    int digits = 0;
    int position = 0;
    while(sin != 0){
        sin_array[position] = sin % 10;
        digits += 1;
        position += 1;
        sin = sin / 10;
    }
    if (digits != 9){
        return 1;
    }
    else{
        return 0;
    }
}

// TODO: Implement check_sin
/*
 * Return 0 if the given sin_array is a valid SIN, and 1 otherwise.
 */
int check_sin(int *sin_array) {
    // total starts off at 0
    int sin_total = 0;
    // loop over it
    for (int position = 0; position < 8; position++){
        // if at an even position just multiply that by 1
        if(position % 2 == 0){
            sin_total += sin_array[position];
        }
        // if not, multiply it by 2
        else{
            if (((2 * sin_array[position]) / 10) != 0){
                int temp = sin_array[position];
                while(temp != 0){
                    sin_total += temp % 10;
                    temp = temp / 10;
                }
            }
            else{
                sin_total += (2 * sin_array[position]);
            }
            // if the product is only one digit
            // need to add some code to handle if it's 2 digits.
            // in this case add the two digits together AND THEN add that to the total.
        }
    }
    // if the total is divisible by 10 it is a valid SIN
    if (sin_total % 10 == 0){
        return 0;
    }
    // else, it's NOT a valid SIN
    else{
        return 1;
    }
}
