How to compile c & c++ programs?
There are several issues with your test source package.
My guess is that you are trying to compile using slightly older C++ standards (gcc
instead of g++
) and probably based on a Windows routine (using conio
).
I've tidied up the test program for you:
#include <iostream> /* dont need .h */
using namespace std; /* use a namespace */
/* #include <conio.h> this is a windows header - dont need */
class fact
{
int i;
static int count;
public :
void calculate()
{
long int fact1=1;
count++;
for (i = 2; i <= count; i++)
{
fact1 *= i;
}
cout << "\nFactorial of " << count << '=' << fact1 << '\n';
}
};
int fact :: count;
int main(void) /* you had an invalid main declaration */
{
int i;
/* clrscr(); not necessary */
fact f;
for (i = 1; i <= 15; i++)
{
f.calculate();
}
/* getch(); not necessary */
return 0; /* need to return a standard value */
}
then compile using
g++ factorial.cpp -o factorial