Function Call problem..

While running it gives the runtime error: "Extra parameter in call to factorial."
Then whats to be done? Need the reply fast..thanks :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream.h>
#include<conio.h>
int factorial(long int);
void main()
{
 clrscr();
 long int a;
 cout<<"This program displays the factorial of the number you enter."<<endl;
 cout<<"Enter the number: ";
 cin>>a;
 cout<<"The factorial of the number you entered is: "<<factorial(a);
 getch();
}
int factorial(long int x)
{
  long int p=1;
 for(int i=x; i>0;i--)
  p*=i;
 return p;
}
Last edited on
1. <iostream.h> is deprecated, you need to use <iostream> without .h
2. <conio.h> is non-standard
3. The function prototype on line 3 takes no parameters, you call it on line 11 with one parameters, and you define an unrelated function with the same name on line 14
So you mean that I have to pass a parameter in line 3 itself?
But only <iostream> without any h is not a header file as taught to me in school! :|
Your school lied to you: http://www.cplusplus.com/reference/iostream/
(A lot of professors haven't kept up with the times and are teaching old archaic C and C++ practices)

On line 3 it should be int factorial(long int);
Last edited on
But I guess its c++turbo...I entered the <iostream> file but then it says.."could not open the file iostream"..maybe then there is something wrong with that...and ok the program runs on editing line 3 but it doesnt give the output even then :| ..thanks for your help till now :)
You should use a more modern compiler ;)
I cant! Thats what is in the syllabus of c++..and thats whats comes in the exams :/
Then I'm very very sorry for you, you'll just have to suffer through your assignments writing deprecated code until you complete the course and will be able to use modern C++ :(

As for your code, don't you think you should return p and not i which no longer exists?
Last edited on
Yeah sorry I had done that in my code but not here..
still its not giving the correct output..
I updated the code now ;)
Last edited on
Well, you call factorial, and it returns a value. Have you considered, you know, printing out the value it returns? ;)
Ok ...could you please copy paste the whole new code..assuming that you are using my version of c++? :P :)
What's to copy paste? You literally just write cout << factorial(a); on line 11...
Hey..it is working..but only till the number entered by the user is 15.
what should be the type decalaration of p then? its long int right now..
Have you tried unsigned long long int? It is 64 bits, whereas long int is probably only 32
Yeah thanks :)
Thanks for the help! It worked :D
Topic archived. No new replies allowed.