a.cpp: In function ‘int main()’:
a.cpp:39: error: no matching function for call to ‘find(int&, int)’
#include <iostream>
#include <fstream>


using namespace std;

int minutes, seconds;
char temp;
int array_l;
bool* sees;
int* a;
int saade;


int main()
{
  ifstream sisf("raadio.sis");
  ofstream valf("raadio.val");
  /*
   * How many songs?
   */
  sisf >> array_l;
  int a[array_l];
  /*
   * Read info and putting info in array
   */
  for (int i = 0; i < array_l; i++)
  {
    sisf >> minutes >> temp >> seconds;
    a[i] = 60 * minutes + seconds;
    cout << a[i] << endl;
  }
  sisf >> minutes >> temp >> seconds;
  saade = 60 * minutes + seconds;
  
  bool ok = find(saade, 0);
  
  if (ok)
  {
    valf << "JAH" << "\n";
    int n = 0;
    for (int i = 0; i < sizeof(sees); ++i)
    {
      if (sees[i])
      {
	++n;
      }
      valf << n << endl;
    }
  }
  
  return 0;
}


bool find(int saade, int i)
{
  if (saade == 0)
  {
    return true;
  }
  if (saade < 0)
  {
    return false;
  }
  if (i == sizeof(saade))
  {
    return false;
  }
  if (find(saade - a[i], i + 1))
  {
    return true;
  }
  sees[i] = false;
  return find(saade, i + 1);
}

Declare find() before main() and it should work.

bool find(int&,int)

Edited 6 Years Ago by vidit_X: n/a

Did you post all of your code? The error is flagging line 39, but find() is called on line 36 of your post... I see nothing wrong with that line.

That being said, vidit is correct. You don't have a prototype for find() before main() so it doesn't know that find() exists yet.

#include <iostream>
#include <fstream>

using namespace std;

int minutes, seconds;
char temp;
int array_l;
bool* sees;
int* a;
int saade;
bool ok;

ifstream sisf("raadio.sis");
ofstream valf("raadio.val");

bool find(int saade, int i)
{
  if (saade == 0)
  {
    return true;
  }
  if (saade < 0)
  {
    return false;
  }
  if (i == sizeof(saade))
  {
    return false;
  }
  if (find(saade - a[i], i + 1))
  {
    return true;
  }
  sees[i] = false;
  return find(saade, i + 1);
}

int main()
{
  /*
   * How many songs?
   */
  sisf >> array_l;
  int a[array_l];
  /*
   * Read info and putting info in array
   */
  for (int i = 0; i < array_l; i++)
  {
    sisf >> minutes >> temp >> seconds;
    a[i] = 60 * minutes + seconds;
  }
  sisf >> minutes >> temp >> seconds;
  sisf.close();
  
  saade = 60 * minutes + seconds;
  
  int sees[array_l]; 
  
  ok = find(saade, 0);
  
  cout << sizeof(sees) << endl;
  
  if (ok)
  {
    valf << "JAH" << "\n";
    int n = 0;
    for (int i = 0; i < sizeof(sees); ++i)
      if (sees[i])
      {
	++n; // Lugude arv
      }
    valf << n << endl;
    for (int i = 0; i < sizeof(sees); ++i)
      if (sees[i]) 
      {
	valf << i + 1 << endl;
	if (--n > 0)
	{
	  valf << " ";
	}
      }
      valf << "\n";
  } else {
    valf << "EI" << endl;
  }
  valf.close();
  return 0;
}
Segmentation fault

Edited 6 Years Ago by vello: n/a

Line 10 defines a variable named "a". Line 45 also defines a variable named "a". Which one do you expect your "find" function to use in line 31, and why?

Also, while we're at it, lines 44-45 and 59 are not legal in standard C++: The size of an array must be known at compile time. If you want something that acts like an array but can have its size determined at run time, use a vector.

This question has already been answered. Start a new discussion instead.