What is wrong with this code? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

What is wrong with this code?

I have written a code to compute the factorial of numbers but is showing errors. https://code.sololearn.com/cpJzFyX8VU7i/?ref=app

24th Sep 2018, 3:55 AM
Kavish Bamboli
Kavish Bamboli - avatar
10 Antworten
+ 5
Hi! You can see and analize this code: https://code.sololearn.com/cggT1zkn0027/?ref=app
24th Sep 2018, 5:58 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar
+ 4
Well, if your method returns an int value, your method must be int type; if your method returns a float value, your method must be float type; etc.
25th Sep 2018, 4:21 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar
+ 3
To make your recursive factorial function work, you need to have a return statement: if (n == 1) return 1; return n * factorial(n - 1);
24th Sep 2018, 4:27 AM
Zeke Williams
Zeke Williams - avatar
+ 3
No Kavish Bamboli . Take a look at what Nimrod A. Holguín L. posted, and hopefully you will understand what I am talking about. Good luck!
24th Sep 2018, 12:53 PM
Zeke Williams
Zeke Williams - avatar
+ 3
And if your method doesn’t return a value, it must be "void".
25th Sep 2018, 4:23 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar
+ 3
You're welcome, Kavish Bamboli! 👍
25th Sep 2018, 4:31 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar
+ 2
Yup, Thank you very much for your help Nimrod A. Holguín L. & Zeke Williams
25th Sep 2018, 4:29 AM
Kavish Bamboli
Kavish Bamboli - avatar
+ 2
Of course Kavish Bamboli ! Happy Coding to you both.
25th Sep 2018, 1:04 PM
Zeke Williams
Zeke Williams - avatar
+ 1
So, the point is that the method must be of an int type that returns a value
25th Sep 2018, 4:16 AM
Kavish Bamboli
Kavish Bamboli - avatar
0
It is the same thing. You use method of type int or void, it is going to return the same value
24th Sep 2018, 4:50 AM
Kavish Bamboli
Kavish Bamboli - avatar