Write a C++ program that takes two integers as input and calculates their greatest common divisor (GCD) using the Euclidean algorithm. The program should be able to handle negative numbers and provide appropriate error messages for invalid inputs.
PLAINFORMAT
#include <iostream>
#include <cstdlib>

// Function to calculate the GCD using Euclidean algorithm
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return abs(a);
}

int main() {
    int num1, num2;

    // Input first integer
    std::cout << "Enter the first integer: ";
    if (!(std::cin >> num1)) {
        std::cerr << "Invalid input. Please enter an integer." << std::endl;
        return 1;
    }

    // Input second integer
    std::cout << "Enter the second integer: ";
    if (!(std::cin >> num2)) {
        std::cerr << "Invalid input. Please enter an integer." << std::endl;
        return 1;
    }

    // Calculate and display the GCD
    int result = gcd(num1, num2);
    std::cout << "The greatest common divisor of " << num1 << " and " << num2 << " is: " << result << std::endl;

    return 0;
}