Name: Anonymous 2010-09-30 6:02
Just started C++, Im required to make a program that finds the factorial of a entered number.
I keep getting this error
"`main' must return `int'"
Google wasn't much use
Heres my code:
#include <iostream>
using namespace std;
int factorial( int num);
void main()
{
cout <<"Enter a number to find the factorial of"<<endl;
int num, ans;
cin >>num;
ans = factorial(num);
cout <<"The value of the factortial of " <<num <<" is " <<ans<<endl;
}
int factorial( int num)
{
int fact = 1;
for( int i = fact + 1; i <=(num + 1); i++)
{
fact = fact * i;
}
return fact;
}
I keep getting this error
"`main' must return `int'"
Google wasn't much use
Heres my code:
#include <iostream>
using namespace std;
int factorial( int num);
void main()
{
cout <<"Enter a number to find the factorial of"<<endl;
int num, ans;
cin >>num;
ans = factorial(num);
cout <<"The value of the factortial of " <<num <<" is " <<ans<<endl;
}
int factorial( int num)
{
int fact = 1;
for( int i = fact + 1; i <=(num + 1); i++)
{
fact = fact * i;
}
return fact;
}