compiler showing error illegal use of pointer

#include<iostream.h>
#include<conio.h>

long fact(int n) ;
int i;
int main()

{clrscr();
long a, n;

cout<<"enter the number ";
cin>>n;
fact(n);
cout<<"factorial is "<<fact(n);

getch();
}
long fact (int x)
{
for(int i=1;i<=x;i++)
{fact=fact*i;
}
getch();
}
Put the code you need help with here.
[/code]
Last edited on
Line 21:
 
fact=fact*i;


fact is not a variable. It's the address of your function i.e. a pointer.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

long fact(long number);

int main()
{
   long number = 0;

   std::cout << "enter the number: ";
   std::cin >> number;

   std::cout << "factorial of " << number << " is " << fact(number) << "\n";
}


long fact (long number)
{
   long fact = 1;

   for (int i = 1; i <= number; i++)
   {
      fact *= i;
   }

   return fact;
}
Topic archived. No new replies allowed.