Hello. Can someone please help me with my code? So I have to write a code that does factorials but excludes even numbers from the facrorial. Like 3! would be 4 not 6. I have written the code for the facrorial but I don't know how to exclude the even numbers. I know to use if(n%2==0) but I'm not sure what to do after that. If someone could help, I would really appricate it. Thank you!
#include <iostream>
using namespace std;
int factorial(int n);
int main ()
{
int x;
int fact;
cin >> x;
fact=factorial(x);
if(x <= 0)
{
cout << "0" << endl;
}
else
{
cout << fact << endl;
}
return 0;
}
int factorial(int n)
{
int product = 1;
while (n > 0)
if(n%2==0)
{
//I don’t know what to do here.
}
{
product = n * product;
n--;
}
return product;
}