code to find the factorial of a number in C++

#include <iostream>

// Function to calculate the factorial of a number
int calculateFactorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    } else {
        return n * calculateFactorial(n - 1);
    }
}

// Main function
int main() {
    // Input: Get the number from the user
    int num;
    std::cout << "Enter a non-negative integer: ";
    std::cin >> num;

    // Check if the input is non-negative
    if (num < 0) {
        std::cout << "Factorial is undefined for negative numbers." << std::endl;
    } else {
        // Calculate and display the factorial
        int result = calculateFactorial(num);
        std::cout << "Factorial of " << num << " is: " << result << std::endl;
    }

    return 0;
}