Function not working correctly

Why isn't my function accepting other inputs for the second and third. It just spits out random giant numbers for highest


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
130
131
132
133
134
135
136
 #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);
   showResults(first, second, third);
   cin >> first;
   
   
   setSecond(second);
   showResults(first, second, third);
   cin >> second;
   
   
   setThird(third);
   showResults(first, second, third);
   cin >> 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);

   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)>second && getFirst(first)<third)
      middle = first;
   if(getSecond(second)>third && getSecond(second)<first)
      middle = second;
   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;
     
}
You copy-pasted declarations into your main method. Also your methods already call cin(), so you don't need to call it again, and you only want to show your results once, when you have all three. Should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
   int first;
   int second;
   int third;
   
   setFirst(first);
   setSecond(second);
   setThird(third);
   
   showResults(first, second, third);
   
   return 0;
}
Topic archived. No new replies allowed.