if (d>1)
return (d*factorial(d-1));
else
return(1);
}
this is my program, my problem is im getting local function definition are illegal, what seems to be incorrect in my code...im using a cse statement to show each fuction parameter!...
Here is a working program. There were many issues
1) brackets were not matching
2) declarion after case x: is not allowed so get the number to process befor the switch statement
Please compare code and see the modifications
# include <iostream>
usingnamespace std;
void caller(void);
int caller2(void);
int caller3(int x);
void caller4(int x);
int divide(int b,int c=2)
{
int r;
r=b/c;
return (r);
}
double factorial (double d);
main()
{
int a;
int x;
double number;
do{
// display menu
cout<<"\n";
cout<<"Menu";
cout<<"1.Function w/o return and Parameter"<<endl;
cout<<"2.Function w/ return w/o Parameter"<<endl;
cout<<"3.Function w/ return and Parameter"<<endl;
cout<<"4.Function w/o return w/ Parameter"<<endl;
cout<<"5.Default parameter function"<<endl;
cout<<"6.Recursive Function"<<endl;
cout << "TO STOP type any number greater than 6 or less than 1\n";
// get the number from user
cout<<"enter Menu\n Menu:";
cin>>x; // store it in x
cout<<endl;
if(x>2 && x<=6){ // then we need another number to some of the process, get that number
cout << "Enter a number\n";
cin >> a;
}
// depending upon the value of x do different things
switch (x)
{
case 1:
caller();
break;
case 2:
cout<<caller2();
break;
case 3:
cout<< caller3(a);
break;
case 4:
caller4(a);
break;
case 5:
cout<<divide(12);
cout<<endl;
cout<<divide(20,4);
cout<<endl;
break;
case 6:
cout<<a<<" factorial is: "<<factorial(a)<<"\n";
break;
}//end switch
}while(x>=1 && x<=6);
return 0;
}
void caller(void)
{
int a;
cout<<"Enter digit\n";
cin>>a;
cout<<endl;
a=a*a*a;
cout<<a<<"\n";
}
int caller2(void)
{
int a;
cout<<"enter digit:";
cin>>a;
a=a*a*a;
cout<<endl;
return a;
}
int caller3(int x)
{
x=x*x*x;
return x;
}
void caller4(int x)
{
x=x*x*x;
cout<<x;
cout<<endl;
}
double factorial (double d)
{
if (d>1)
return (d*factorial(d-1));
elsereturn(1);
}