My program is supposed to count the number of vowels in a file using recursion. When I run this program I always get the number of vowels is 0. I'm pretty sure that is because it outputs the value for length instead the value for vowelcount but I don't understand why length is 0 anyway. Please help.
two things you can try mate dont know if it will help as im a noob to but i think you program is returning 0 so remove the return 0;
and on the last line try
return vowels(letters = letters+1, vowelcount, length-1);
hope i help
yes I had a broblem a bit like that I remove the return 0 and it worked i think it was because of having 2 return functions
not to sure but worth a try
@OP:
Look up "passing by reference" vs. "passing by copy"...
Also, you can make this program easier by working with strings, instead of char[]s.
@markkirby: return 0 in main is fine. It explicitly says (to your OS) that your program ran correctly. And I would look up how recursion works because I don't think that line of code does what you want it to do...!
If I remove the return 0 I don't know what to replace it with. I tried replacing it with return vowelcount but that is still 0 too. I also changed the last line toreturn vowels(letters = letters+1, vowelcount, length-1); ; but nothing changed. I hate recursion.
@mathhead
Originally my program was using strings and I decided to switch to an array because I had no idea how to go about checking if each letter was a vowel. The only way that I know how to check each letter in a line of characters is through an array. I'll try it again and see if I can get anything to work.
@kapo
Yes he is. I could do this with no problem using loops.