my cpp

#include <iostream>

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

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

    // Check if the entered number is non-negative
    if (number < 0) {
        std::cout << "Please enter a non-negative integer." << std::endl;
        return 1; // Exit the program with an error code
    }

    // Calculate and output the factorial of the entered number
    int result = factorial(number);
    std::cout << "Factorial of " << number << " is: " << result << std::endl;

    return 0; // Exit the program successfully
}