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.
#include <iostream>
usingnamespace 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 (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.
#include <iostream>
usingnamespace 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;
}