0

Please tell me how to remove error

#include <iostream> using namespace std; void func(int x,int y) { int z; z=x+y; return z;} int main() { return 0; }

5th Dec 2017, 11:32 AM
Anuj kumar
Anuj kumar - avatar
8 Answers
+ 8
first of all your function is of void type and u r trying to return a value "z" and another thing is that it is not called in main function. so either make the function of int type and then call it to main method. #include <iostream> using namespace std; int func(int x,int y) { int z; z=x+y; return z;} int main() { cout<<func(4,5); return 0; } OR let your function be of void type and pass the argument from the main method and don't return any value.. print the value of "z" directly in "func()" function. #include <iostream> using namespace std; void func(int x,int y) { int z; z=x+y; cout<<z;} int main() { func(4,5); return 0; }
5th Dec 2017, 11:39 AM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
+ 3
I don't understand, you have made more complex codes than this. Why can 't you fix it yourself.
5th Dec 2017, 11:42 AM
Paul
Paul - avatar
+ 1
@ Anuj kumar In line 3, You have to declare constant at last, it is necessary to declare variables first in function parameters Solved: int func(int n, int m = 10){
5th Dec 2017, 11:47 AM
#RahulVerma
#RahulVerma - avatar
0
thanks everyone
5th Dec 2017, 11:43 AM
Anuj kumar
Anuj kumar - avatar
0
#include <iostream> using namespace std; int func(int m=10,int n){ int c; c=m+n; return c; } int main() { cout<<func(5); return 0; } and how solve this ?
5th Dec 2017, 11:45 AM
Anuj kumar
Anuj kumar - avatar
0
how to solve ?
5th Dec 2017, 11:50 AM
Anuj kumar
Anuj kumar - avatar