I've got a very specific homework problem I am working on. I am supposed to find the semi or double factorial of any given positive integer. My program works fine with evens, but not odds. What am I missing?
//doubleFactorial.cpp
//Take integer input and compute the double factorial
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(){
unsignedlong i, num, fact = 1;
cout <<"enter integer: " << endl;
cin >> num;
i = num;
if(num == 0)
fact = 1;
elseif(num == -1)
fact = 1;
elseif(num % 2 == 0 && num >= 2)
while(num)
{
fact *= num;
num -= 2;
}
elseif(num % 2 !=0 && num >= 1)
while(num >= 1)
{
fact *= num;
num -= 2;
}
cout << "The double or semifactorial of " << i << " is " << fact << endl;
return 0;
}
I sit here, pencil testing it, and I can't find my logic error. This code compiles without a hitch. Throw it an odd number and it just sits there, blinking a cursor at me... and laughing.