#include<iostream>

using namespace std;
int fact (int num);
int main () {
	cout<<"Enter a number"<<endl;
	int number;
	cin>>number;
	cout<<"Displaying number: "<<number<<endl;
	cout<<"Calculating Factorial for the number"<<endl;
	int fact;
	fact = fact(number);
	return 0;
}

 int fact (int num)
 {
 	
 	if(num==1)
 	{
 		return num;
 	}
 	else 
 	{
		return num * fact(num -1);
 	}
 }

This program gives the following error:
fact cannot be used as a function.
could someone help me on this issue

Salem commented: 4 years late with the thread hijack, and no code tags. -6

Recommended Answers

All 9 Replies

> fact = fact(number);
How does the compiler decide what you mean?

commented: Good point :) +1
commented: Your post was the limit to this thread buddy nothing could be added ;) +2
commented: Excellent! +8

Change "int fact;" to "int anotherVariable;"

@NeoKyrgyz : Did your post add even an inch to what Salem had said ? Was that really necessary ? (Salem's post was the reason many others didn't post because it rectifies everything with respect to this thread.:) and nothing more could be added.)

nothing more could be added.

well... he could rewrite the entire code with full comments, perform validation and coverage metrics, compile release executables and build distribution kits for several major operating systems, then upload the packages to SourceForge and other repositories.

or he could just continue spitting out redundantly obvious answers that others had already pointed out.

either way.

commented: He will now think Oh! So many possibilities are there,it never came to my mind !!! ;) Cool one there buddy !!! +2
commented: But still a very useless post. Didn't you just complain about someone else's useless post? ;) -4

well guys, I thought before posting.
A person who couldn't resolve this kind of error, wouldn't understand the explaination of Salem, which is just a little bit more desciptive than compiler error

"fact cannot be used as a function"

commented: Agreed. +10
commented: Disagreed. -2

i feel ya bro.

it's just the culture here is that we'd rather teach a person to fish than give them fish.

>A person who couldn't resolve this kind of error, wouldn't understand the explaination of Salem.

We all started at that stage itself and we are still learning here so its better not to talk lightly of someone,because we all lack something or the other.

And I would like to mark this in bold with all credits to jephthah :
"It's just the culture here is that we'd rather teach a person to fish than give them fish."

We all started at that stage itself and we are still learning here so its better not to talk lightly of someone,because we all lack something or the other.

That's the point. We all started at that stage, and it's good idea to give more information than compiler does in order to be helpful. I'm not accusing him/her for lack of knowledge, I'm not expert either - but I just wanted to note (inform you) that he's beginner.

And, this is not the place for such discussions, open another thread, I'll reply to you there.

your Mistake is
int fact;
fact = fact(number);
write it like
int f;
f= fact(number);

commented: hey, don't bother reading the previous 9 posts, or anything. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.