+ 2

Why this code does not execute properly?

int multiply(int a, int b){a * b;} I found these code at codewars.com and try to solve it several times but keep failing.

1st Jan 2018, 5:45 AM
boyd
boyd - avatar
5 odpowiedzi
+ 15
you have to return a * b; so: int multiply(int a, int b) { return a * b; }
1st Jan 2018, 5:48 AM
Cool Codin
Cool Codin - avatar
+ 1
oh.. thats it? :'v .. lul i try everything i knew but not this one.. thanks.. btw why i have to return a*b ?
1st Jan 2018, 6:04 AM
boyd
boyd - avatar
+ 1
when you return a*b, the product of both numbers will recieved by the main function. For eg: cout<<multiply(4,5); The values will be pass to the function n the function will return the product (i.e., 20), which will be printed on screen as output.
1st Jan 2018, 6:24 AM
Harjeet Singh
Harjeet Singh - avatar
+ 1
you didn't have written the return keyword it should be like int multiply (int a, int b) { return a*b; }
1st Jan 2018, 6:28 AM
Rishabh
Rishabh - avatar