So this is my second project in C++, but I'm having some trouble understanding Recursive functions.
We are supposed to write a program that has a recursive function. And the program should ask the user for a number. And then display the number of even digits that the number had.
ie. input: 22378
output: the number had 3 even digits on it
So far this is my code, but I'm having lots of trouble with the recursive
#include <iostream>
using namespace std;
int howManyEven (int);
int main (){
int number, again = 1;
while (again == 1){
cout << "Please enter any number: ";
cin >> number;
cout << "Your number had " << howManyEven(number) << " even digits on it. \n";
cout << "Want to do it again? (1) = YES (0) = NO: ";
cin >> again;
}
return 0;
}
int howManyEven(int n){
if (n%2 == 0)
return 1;
return howManyEven(n/10);
}