[Tutor] recursive function

Alan Gauld alan.gauld@blueyonder.co.uk
Sat May 31 17:51:08 2003


> i need to use recursive fuction insted of while loop in the
following
> program .

Since the code should work this looks suspiciously like a homework
assignment! However I'll give you the benefit of some doubt and
suggest an approach.

You want a function that takes a string argument and
   if the string is empty returns zero
   else it reads the first character and
        if it is a number adds it to the value from the rest of the
string
        else it adds zero to the value from the rest of the string

>  does anybody  have any good ideas how to do that?

FWIW my version took 5 lines of code, so the end result should be a
lot
shorter than your current version!

Now you try building that. If you don't get it to work show us
what you've done and we might be able to help further.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld