Help with syntax on function

Can i get some help on how to get the getMiddle function working? My syntax isnt working ive tried a bunch of things and nothing is working too well

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>


using namespace std;

void setFirst(int& first);
void setSecond(int& second);
void setThird(int& third);

int getFirst(int& first);
int getSecond(int& second);
int getThird(int& third);

int getHighest(int first, int second, int third);
int getLowest(int first, int second, int third);
int getMiddle(int first, int second, int third);

void showResults(int first, int second, int third);

int main(){

   int first;
   int second;
   int third;
   
   setFirst(first);
   setSecond(second);
   setThird(third);
   
   showResults(first, second, third);
   
   return 0;
}

void setFirst(int& first)
{
   cout << "please enter the first number: ";
   cin >> first;
}

void setSecond(int& second)
{
   cout << "please enter the second number: ";
   cin >> second;
}

void setThird(int& third)
{
   cout << "please enter the third number: ";
   cin >> third;
}

int getFirst(int& first)
{
   return first;
}

int getSecond(int& second)
{
   return second;
}


int getThird(int& third)
{
   return third;
}


int getHighest(int first, int second, int third)
{
   int highest;
   
   
   if(getFirst(first)>second && third)
      highest = first;
   if(getSecond(second)>third && first)
      highest = second;
   if(getThird(third)>second && first)
      highest = third;
      
   return highest;
}

int getLowest(int first, int second, int third)
{
   int lowest;
   
     
   if(getFirst(first)<second && third)
      lowest = first;
   if(getSecond(second)<third && first)
      lowest = second;
   if(getThird(third)<second && first)
      lowest = third;
      
   return lowest;
}

int getMiddle(int first, int second, int third)
{
   int middle;
      
   if(getFirst(first)<third && getFirst(first)>second); 
      middle = first;
   if(getFirst(first)>third && getFirst(first)<second);
      middle = first;
   if(getSecond(second)<third && getSecond(second)>first);
      middle = second;
   if(getSecond(second)>third && getSecond(second)>first);
      middle = second;   
   if(getThird(third)<second && getThird(third)>first);
      middle = third;
   if(getThird(third)<second && getThird(third)<first);
      middle = third;
      
   return middle;
}

void showResults(int first, int second, int third){
   cout << "the highest value was: "
        << getHighest(first, second, third) << endl;
   cout << "the middle value was: "
        << getMiddle(first,second,third) << endl;
   cout << "the lowest value was: "
        << getLowest(first,second,third) << endl;
     
}
}
1
2
3
int getFirst(int& first);
int getSecond(int& second);
int getThird(int& third);

You don't need these, just use the variable directly.

Remove line 129.

It would be easier to store these numbers in an array, sort the array an then just pick out the lowest, highest, and middle. Meanwhile, here is your code without the get() functions.
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
#include <iostream>

using namespace std;

void setFirst(int &first);
void setSecond(int &second);
void setThird(int &third);

int getHighest(int first, int second, int third);
int getLowest(int first, int second, int third);
int getMiddle(int first, int second, int third);

void showResults(int first, int second, int third);

int
main()
{

    int first;
    int second;
    int third;

    setFirst(first);
    setSecond(second);
    setThird(third);

    showResults(first, second, third);

    return 0;
}

void
setFirst(int &first)
{
    cout << "please enter the first number: ";
    cin >> first;
}

void
setSecond(int &second)
{
    cout << "please enter the second number: ";
    cin >> second;
}

void
setThird(int &third)
{
    cout << "please enter the third number: ";
    cin >> third;
}

int
getHighest(int first, int second, int third)
{
    int highest;

    if (first > second && third)
	highest = first;
    if (second > third && first)
	highest = second;
    if (third > second && first)
	highest = third;

    return highest;
}

int
getLowest(int first, int second, int third)
{
    int lowest;

    if (first < second && third)
	lowest = first;
    if (second < third && first)
	lowest = second;
    if (third < second && first)
	lowest = third;

    return lowest;
}

int
getMiddle(int first, int second, int third)
{
    int middle;

    if (first < third && first > second);
    middle = first;
    if (first > third && first < second);
    middle = first;
    if (second < third && second > first);
    middle = second;
    if (second > third && second > first);
    middle = second;
    if (third < second && third > first);
    middle = third;
    if (third < second && third < first);
    middle = third;

    return middle;
}

void
showResults(int first, int second, int third)
{
    cout << "the highest value was: " << getHighest(first, second, third) << endl;
    cout << "the middle value was: " << getMiddle(first, second, third) << endl;
    cout << "the lowest value was: " << getLowest(first, second, third) << endl;

}


Part of the assignment is to use the gets unfortunately. Here are each of the requirements
3 variables, all integers, NOT global in scope!
3 "set" functions, one for each variable, used to accept user input and set the value of each variable
3 "get" function, one for each variable, that accepts the variable as a parameter, and returns the value of each variable
1 function, getHighest, that accepts all 3 variables as parameters and returns the highest of them.
1 function, getLowest, that accepts all 3 variables as parameters and returns the lowest of them.
1 function, getMiddle, that accepts all 3 variables as parameters and returns the middle value.
* we will assume all 3 values are unique. you don't have to check for equality
1 function, showResults, that accepts all 3 variables as parameters and outputs the results to the user.
I know this sounds like a lot for a lab, but we will do 1/3 of it together in class, which should make it pretty simple.
3 variables, all integers, NOT global in scope!

It sounds like there should be a class in here somewhere. Can you post the whole assignment?
Interesting trail you're building here, aaronpeart. Let's take a trip down memory lane:

"Help with this program?"
last post Feb 23, 2018 4:32pm
http://www.cplusplus.com/forum/general/231566/

"Function not working correctly"
Feb 23, 2018 at 3:51pm
http://www.cplusplus.com/forum/beginner/231597/
Here I wrote that you copy-pasted declarations into your main(), and so you fixed that in another thread...

"Help with syntax on function"
Feb 23, 2018 at 5:21pm
http://www.cplusplus.com/forum/beginner/231600/
Omg, that's this post!!!

Really, can you just keep it all in one thread, lol. It's all still the same program =)

I was really hoping you could now zero in on the problematic method causing logical errors, which is just your getMiddle. Hint: std::min , std::max are your friends.
Topic archived. No new replies allowed.