function problem, please help.

Write your question here.
So I'm really new and I just don't understand why my code can't work.
For my function it can't return to average.
Also, line 10 it show value not ignored as it ought to be.
Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <iostream>
using namespace std;

void king (int &x, int &b);

int main ()
{
	int a, b;

   int answer = king(a,b);
    
    return answer;
   
}

void king(int &x , int &b)
{
	cin >> x;
	cin >> b;
	
	int average = (x+b)/2;
	
	return average;
}
void king (int &x, int &b);

http://www.thefreedictionary.com/void
void  (void)
adj.
  1. Containing no matter; empty.
  2. Not occupied; unfilled.
  3. Completely lacking; devoid: void of understanding. See Synonyms at empty.
  4. Ineffective; useless.
  [...]
n.
  1.
    a. An empty space.
    b. A vacuum.
  [...]
You just declared king as returning nothing.
On line 10 you are trying to assign (adj:3) voidnothing to variable, which is (adj:4) voiduseless.
On line 23 you are throwing your average variable away.
You should also probably use floats as the average may not be an integer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <iostream>
using namespace std;

int king (int &x, int &b);

int main ()
{
	int a, b;

   int answer = king(a,b);
    
   cout << answer << endl;
   
}

int king(int &x , int &b)
{
	cin >> x;
	cin >> b;
	
	int average = (x+b)/2;
	
	return average;
}

thanks for the reply, but i still get stuck.
how should i fix it ?
Topic archived. No new replies allowed.