+ 1

Help me with this code i did not understand my mistake

https://code.sololearn.com/cbfRaG8eD2lc/?ref=app

27th Feb 2018, 6:25 PM
Basit Mir
Basit Mir - avatar
2 odpowiedzi
+ 2
First problem, you didn't declare 'num2.' Just like you put 'int' in front of num1 when you declared/called your function, you'll do the same for num2. CHANGE: int max(int num1, num2); TO: int max(int num1, int num2); Second problem, you have a semi-colon when you're calling your function, remove that and the function can execute. CHANGE: int max(int num1, num2); { } TO: int max(int num1, int num2) { } Your corrected code is below: https://code.sololearn.com/ctz2DLm1V32m/#cpp #include <iostream> using namespace std; // function declaration int max(int num1, int num2); int main () { int a = 100; int b = 200; int ret; // calling a function to get max value. ret = max(a,b); cout << "max value is:" << ret << endl; return 0; } // function returning the max between two numbers int max(int num1, int num2) { // local variable declaration int result; if (num1 > num2){ result =num1; } else { result = num2; } return result; }
27th Feb 2018, 6:42 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
thanks
27th Feb 2018, 6:50 PM
Basit Mir
Basit Mir - avatar