# problem with recursion

Page 1 of 1

## 2 Replies - 659 Views - Last Post: 02 January 2009 - 07:56 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=79040&amp;s=48477e02d978cdf61931f79ea0264ee5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rafi1082

Reputation: -1
• Posts: 8
• Joined: 02-January 09

# problem with recursion

Posted 02 January 2009 - 05:24 AM

the program sepose to check if the number of times that a digit is shown in a number is an odd or a pair times and print 1 or 0 in a match
i am getting this error
Error 1 error C2664: 'time' : cannot convert parameter 1 from 'int [250]' to 'int' c:\c\141\141\141.cpp 36 141

```#include "stdafx.h"
#include "iostream"
using namespace std;
#define SIZE 250

int exict(int a,int b) // check if dig is in the array
{
if (a==b)
return 1;
}

int time (int num, int min, int max, int dig) //recurcion
{
int count;
if (min==max+1)
count++;

return exict(time(num, min,((min+max)/2),dig),time(num,((1+max+min)/2),max,dig));
}

void main()
{
int i,k=0,result,size,dig;
int num[SIZE]={0};

//input
cin>>num[SIZE];
cin>>dig;
for (i=0; i<SIZE; i++)//gets the last loaction of number from the array
{
if (k<num[i])
k=num[i];
}
result=time(num,0,k,dig);
if (result%2)
cout<<1<<"\n";
else
cout<<0<<"\n";
}
```

Is This A Good Question/Topic? 0

## Replies To: problem with recursion

### #2 AmitTheInfinity

• C Surfing ∞

Reputation: 119
• Posts: 1,565
• Joined: 25-January 07

## Re: problem with recursion

Posted 02 January 2009 - 05:48 AM

Your time function signature int time (int num, int min, int max, int dig) //recurcion takes first parameter as integer, but you are sending array from main in call, that's the problem in there. [You need some modifications in that code to make it work with array... I don't thing this one will work even if you make it work by modifying first parameter.]

### #3 gabehabe

• GabehabeSwamp

Reputation: 1399
• Posts: 10,965
• Joined: 06-February 08

## Re: problem with recursion

Posted 02 January 2009 - 07:56 AM

Just about to look over your code, but in the mean time, what's this?
#include "iostream"
"" is for header files which are in the same directory as your project.

Did you mean #include <iostream>?

Oh, and main should always return int, not void.

EDIT:
Right, got it.

It's because you're defining num as an array in your main function, but then you try to pass it to a function which accepts a single int.

I haven't tested it, but did you mean something like int time (int num[], int min, int max, int dig) //recurcion?
Passing an array[] instead of a single int.