solving problem 2 and changing `sum` to `total` in problem 1 because Im retarded and used a reserved word