min, max, middle problem.

I bombard this site way too much, I'm sorry. But I am stuck, once again.

The problem is :Write a program, consisting of two functions:
 main function
 Inputs data: a, b , c – integers
 Calls function: middle function
 Outputs the middle element
 middle function: Calculates the middle element of a set of three numbers
 Example:
The value of middle (17, 2, 10) is 10
 Prototype:
int middle(int, int, int);
Hint: md = (a + b + c) - (mx + mn),
where mx is the maximum and mn is the minimum of {a, b, c}

Here is the code I have so far. I'm not that far from the goal ( I don't think so at least.)
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
//Program consisting of three functions that finds the middle number.
#include <iostream>
using namespace std;
int max3 (int, int, int);// prototype
int min3 (int, int, int); //prototype
int middle (int, int, int); //prototype
void main ()
{
int a;
int b;
int c;
int mx;
int mn;
int md;

cout << "Enter a value for a." << endl;
cin >> a;
cout << "Enter a value for b." << endl;
cin >> b;
cout << "Enter a value for c." << endl;
cin >> c;
 
mx = max3 (a,b,c);
mn = min3 (a, b, c);
md = middle (a,b,c); //a,b,c are arguments.
cout << "Middle number = " << md<< endl;
}

//function definition
int max3 (int a, int b, int c) // int a, b, and c are parameters.
{
return mx = (max (a, max (b,c))
}

//function definition
int min (int a, int b, int c)
{
return mn = (min (a, min (b,c))
}

//function definition
int middle (int a, int b, int c) // int a, b, and c are parameters.
{
return md = (a + b + c) - (mx + mn)
}


I know I'm forgetting the ; after the returns, but I'm still getting other errors as well.
Last edited on
You've used functions called "min" and "max" that are not declared.

(Actually, in the header file <algorithm> you will find exactly those functions which do exactly what you want. You should #include <algorithm>).

Also, return mx = ....;

mx is not declared anywhere. You can simply return ...; and forget the mx =.

Your middle function... again, mx and mn are not declared. You really want
mx to be the max of a,b,c. You already have a function that returns that value--
max3. Likewise for mn.
Okay, this is the new code I have now.

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
//Program consisting of three functions that finds the middle number.
#include <iostream>
#include <algorithm>

using namespace std;
int max3 (int, int, int);// prototype
int min3 (int, int, int); //prototype
int middle (int, int, int); //prototype
void main ()
{
int a;
int b;
int c;
int mx;
int mn;
int md;

cout << "Enter a value for a." << endl;
cin >> a;
cout << "Enter a value for b." << endl;
cin >> b;
cout << "Enter a value for c." << endl;
cin >> c;
 
mx = max3 (a,b,c);
mn = min3 (a, b, c);
md = middle (a,b,c); //a,b,c are arguments.
cout << "Middle number = " << md << endl;
}

//function definition
int max3 (int a, int b, int c) // int a, b, and c are parameters.
{
return max (a, max (b,c));
}

//function definition
int min (int a, int b, int c)
{
return min (a, min (b,c));
}

//function definition
int middle (int a, int b, int c) // int a, b, and c are parameters.
{
return (a + b + c) - (max3 + min3);
}


Still receiving error C2296: '+' : illegal, left operand has type 'int (__cdecl *)(int,int,int)'



edit:

new code
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

//Program consisting of three functions that finds the middle number.
#include <iostream>
#include <algorithm>

using namespace std;
int max3 (int, int, int);// prototype
int min3 (int, int, int); //prototype
int middle (int, int, int); //prototype
void main ()
{
int a;
int b;
int c;
int mx;
int mn;
int md;

cout << "Enter a value for a." << endl;
cin >> a;
cout << "Enter a value for b." << endl;
cin >> b;
cout << "Enter a value for c." << endl;
cin >> c;
 
mx = max3 (a,b,c);
mn = min3 (a, b, c);
md = middle (a,b,c); //a,b,c are arguments.
cout << "Middle number = " << md << endl;
}

//function definition
int max3 (int a, int b, int c) // int a, b, and c are parameters.
{
return max (a, max (b,c));
}

//function definition
int min3 (int a, int b, int c)
{
return min (a, min (b,c));
}

//function definition
int middle (int a, int b, int c) // int a, b, and c are parameters.
{
return (a + b + c) - (max (a, max (b,c)) + min (a, min (b,c)));
}


it's longer at the bottom, but it works!!! Thank you so much!
Last edited on
Topic archived. No new replies allowed.