Code error

Please can you help identifying the error within this code. Thank you so much

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
int my_fun(int a, int& b, int c) {

	a = 2 * a + b;
	b = c;
	cout << "In my_fun, a=" << a << " b=" << b << ".\n";

	return a % 2;
}


int main() {

	int x = 1;

	int y = -2;

	int z = 3;

	x = my_fun(x, y, z);

	cout << "In main, x=" << x << " y=" << y << " z=" << z << ".\n";

	Return 0;

}
Firstly you should usually post errors rather than just code, but as it will just run in the shell then I had a look and you have to include iostream in order to use cout (and put std:: before it). Also C++ is case sensitive and all keywords (such as return) are lower case.
Yes I included the iostream. I do not know what the error is hence thats why I added all the code and I edited also all the keyword case sensitive
You're compiler should output an error if it fails to compile. When running it in the shell, the only changes I had to do to make it run were to put #include iostream before anything, put std:: before all uses of cout and to replace Return with return.
Ok thank you. Please can you tell me what was your output because this is an exam question. and whats the use of the std::
This is the output when I run it.
In my_fun, a=0 b=3.
In main, x=0 y=3 z=3.

The std:: is because cout is not just a globally known stream, it is stored within the std namespace used by the standard library.
Thank you. But please what is the function of the program and i think the error is logically because the questions says there is a error
If there is a logic error then you can't know unless you know what the program is meant to do. I don't know this because I don't have access to wherever you got the function from. Also syntax errors count as errors, the most likely thing for it to be talking about it the Return but the others are valid errors.
Now I understand.. Thank you shadowmouse
Topic archived. No new replies allowed.