Recursion-Finding how many times digit six appears in two digit random numbers

I need to make use of recursion, in finding how many times the digit six appears in random numbers that are two digits, so from 10 up to 99 and then i need to print how many times six digit appears.
I'll give you two hints:

1
2
3
4
if( n % 10 == 6 )
  ... //the last (right-most) digit in n is 6
//example
8642 % 10 == 2; //true 

1
2
3
n / 10 == ... //all the digits to the left of the last (right-most) digit in n
//example
8642 / 10 == 864; //true 


Now let's see what code you have.
void sixCount()
{
int r= rand() % 99;
if(r%10==6 && r/10==6)
cout<<r<<endl;
}
dont think thats it but how does it look
One essential element of a recursive method is that the function or method has to be called from within itself.
example:a recursive function that prints a binary numeral for a positive integer
1
2
3
4
5
void print_binary(int n)
{
    if(n>=2) print_binary(n/2);
    cout<<n%2;
}
yea i understand that but how would i get random numbers that have digit six in it but number from 10 to 99
1
2
3
4
5
6
7
//so if the function will print only, void is fine. I'm writing this to "return" the count of digit 6 in int n.
int sixCount(int n) {
	... //here we write the function
	//remember, if( n % 10 == 6 ) then it ends with a 6
	// also, n / 10 = the rest of the number
	return sixCount( ... ); //somewhere we need a recursive call
}

Does this help?
Topic archived. No new replies allowed.