![]() |
|
#1
|
|||
|
|||
Trouble with finding a vowel using recursionI have a project in which I am to find all of the vowels entered in a word using recursion. I've written something, and based on the displays I have in the code, I am parsing the data properly, but the recursion part is undoing my counts. What do I need to do (and undo) to make this work as intended?
CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
Ok firstly: why do you insist doing this with recursion? This kind of problem is far more easily solved by using simple iteration (for(){}).
Secondly To your problem: Your problem lies with variables cnt and dummyVal. Its a bit complicated to explain the reason but here is the correction: Delete the: CPP / C++ / C Code:
Replace your 2 instances of: CPP / C++ / C Code:
CPP / C++ / C Code:
this should remedy your problem. Here's what I think about the reason your original code doesn't work: you count the wovels when the recursion goes "downward" but the information is not passed "upward" and the root of your recursion doesn't get it. Remember that recursion is two way process. By root I mean the point of code that first time calls the recursive function. Pseudo code: CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
|
Thanks for your help. Your solution worked well.
I agree, using an iterative process like a for/loop would have worked quite well; however, the exercise required using recursion. Also thanks for your example on the recursion process. I have a couple more problems I need to solve using recursion, so hopefully I can use your example in solving my remaining exercises. |
|
#4
|
||||
|
||||
|
Quote:
Quote:
Paraphrased: I have been given a task requiring me to: a) find all vowels b) using recursion ;-) ;-) __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Having trouble trying to format C: | Nickster64 | Computer Software Forum - Windows | 2 | 27-Jul-2004 07:31 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The