The error message for the original codes is: unary minus operator applied to unsigned type, result still unsigned. Added static casting to eliminate this message.