[Error] rand.cpp: No such file or directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marwa abdelali
    New Member
    • Oct 2016
    • 2

    [Error] rand.cpp: No such file or directory

    Hello everyone

    I have this code to compile it

    // non deterministic search
    #include <iostream>
    #include <fstream>
    #include "rand.cpp"

    using namespace std;

    const int N=100;

    void loaddata();
    int mysteryfunction (int z);

    int main ()
    {int a[N+1]; int x; int k; int z; int f;
    // array a, item x, index k, parameter z
    // returns random index n of x in a[1..N]
    loaddata(); // loads a and x
    z=1; k=1;
    while (k<=N+1)
    {if ((a[k]==x) && (z>0))
    {f=k; z=mysteryfuncti on(z);}
    k=k+1;}
    cout << f << endl;}

    void loaddata() {SetSeed(2016); cout<<"load data"<<;}

    int mysteryfunction ()
    {return -N + (int) (NextRand() * (2*N+1));}


    but during compilation
    * it shows me


    4 20 C:\Users\marwa\ Desktop\ndsearc h (1) (4).cpp [Error] rand.cpp: No such file or directory


    is there anyone who can help me in solving this problem?
  • marwa abdelali
    New Member
    • Oct 2016
    • 2

    #2
    i replaced #include "rand.cpp" by #include <cstdlib> but Compilation failed I had other errors:

    In function 'void loaddata()':
    26 : error: 'SetSeed' was not declared in this scope
    void loaddata() {SetSeed(2016); cout<<"load data"<<;}
    ^
    26 : error: expected primary-expression before ';' token
    void loaddata() {SetSeed(2016); cout<<"load data"<<;}
    ^
    In function 'int mysteryfunction ()':
    29 : error: 'NextRand' was not declared in this scope
    {return -N + (int) (NextRand() * (2*N+1));}

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      .cpp files do not include .cpp files. This just invites redefinition errors. I would ignore the invalid directory for the moment and work to get that include of rand.cpp out of the program.

      What you should do is add rand.cpp as a source file in your project that compiles the code containing main().

      Then you replace the include of rand.cpp with an include of rand.h. This file you don't have yet so create it. It will contain the function prototypes of the functions that are inside rand.cpp that are called from outside this file.

      Get this part working and then post again on this invalid directory issue. I suspect that since it is a .cpp file it is following the search rules for source files rather than include files.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        You need to include a header that defines SetSeed() and NextRand().

        Comment

        Working...