Why my output is always 0? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why my output is always 0?

The method “show” needs to show how many vowels are in the array, but i always get 0. How can i solve this? https://code.sololearn.com/caK1V1WjL49P/?ref=app

27th Jan 2021, 9:58 PM
Diego Becerril
Diego Becerril - avatar
3 Answers
+ 3
From a quick glance, the variable cont is reconstructed each time the function show() is called (in other words, cont is unique to each stack frame). So you'd have to store the result of show() into cont and then return it when the first condition is no longer met. Edit: Simplified parts of it: https://code.sololearn.com/ca1392a24A2A
27th Jan 2021, 11:17 PM
Mike A
Mike A - avatar
+ 1
hey Diego Becerril that is because you are returing the varible cont which has a value of zero and you are returning cont so no matter the result of the if and switch statements it will always return zero
27th Jan 2021, 11:00 PM
Ollie Q
Ollie Q - avatar
0
Jegix thaaaanks, your code its helpfull
27th Jan 2021, 11:31 PM
Diego Becerril
Diego Becerril - avatar