6 functions using do while in case statement

# include <iostream.h>
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;
do{
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;

switch (x){

case 1:

caller();
break;
case 2:
cout<<caller2();
break;
case 3:
int a;
cout<<"enter digit";
cin>>a;
cout<<endl;
cout<< caller3(a);
break;
case 4:

cout<<"enter digit";
cin>>a;
cout<<endl;
caller4(a);
break;
case 5:
cout<<divide(12);
cout<<endl;
cout<<divide(20,4);
cout<<endl;
break;
case 6:

double number;
cout<<"Enter a number: ";
cin>>number;
cout<<number<<"factorial is: "<<factorial(number);




return 0;
break;

}
while ((x>=1)&&(x<=3))
return 0;
void caller(void)
{
int a;
cout<<"Enter digit";
cin>>a;
cout<<endl;
a=a*a*a;
cout<<a;
}
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));
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

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

# include <iostream>
using namespace 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));
	else
	return(1);
}
Topic archived. No new replies allowed.