New poster to these forums and I'm a bit stuck on this one problem I have for my CIS class. My code for this problem is probably pretty bad at the moment as Im not sure how to proceed from here. C++ is still fairly new to me so if you could help that would be appreciated thanks.
Problem:
Write a recursive C++ function which accepts two parameters .. one int parameter, a value, and another int parameter, a digit and prints the number of times the digit occurs in the value. Write a short C++ main which reads in int value and calls this function.
You are not to use any global variables or add any other parameters to this function.
if ( value is greater than 10 )
{
if ( last digit of value is equal to digit )
return 1 + recursion(value/10, digit)
elsereturn recursion(value/10, digit)
}
elseif ( value is equal to digit )
return 1
elsereturn 0
You're not too far off. It pays to think out the reasoning before you start writing the code.