Hey guys, now I have an assignment to create code that will ask for a number and then calculate the factorial of it with a for loop in a separate function and return the value to main..
Here is my code, I think it looks pretty good, but when I run it it just sends me the black box and it just stays blank with the blinking _ so Im not sure if it is trying to run it or something else is going on.
#include <iostream>
using namespace std;
double factorial(double num); //factorial prototype
void main ()
{
int num;
int answer;
answer= factorial(num);
cout << "Please enter a number: ";
cin >> num;
if (num < 0)
cout <<"Please enter a positive integer.\n";
else
cout <<"Factorial of " << num << " is: " <<answer;
cout << "\n\n";
system ("pause");
}
//compute factorial
double factorial (double num)
{
double answer;
int n;
for (n = 1; n <= num; n++)
{
num *= n;
}
return answer;
}