Ad
  • Default User Avatar

    the "if" statement accounts for those values by subtracting a number from the sum if it is to the left of a larger number

    for instance...

    MCMXC = [1000, 100, 1000, 10, 100]

    if(data[numbers[i]] < data[numbers[i+1])... this is triggered when data[numbers[1]] AKA 100 is less than data[numbers[1+1]] AKA 1000

    so...sum += data[numbers[1+1]] - data[numbers[1]] AKA 1000 - 100