By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,470 Members | 924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,470 IT Pros & Developers. It's quick & easy.

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

P: 2
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=mysteryfunction(z);}
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\ndsearch (1) (4).cpp [Error] rand.cpp: No such file or directory

is there anyone who can help me in solving this problem?
Oct 12 '16 #1
Share this Question
Share on Google+
3 Replies

P: 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));}
Oct 12 '16 #2

Expert Mod 5K+
P: 9,197
.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.
Oct 12 '16 #3

Expert 100+
P: 2,398
You need to include a header that defines SetSeed() and NextRand().
Oct 13 '16 #4

Post your reply

Sign in to post your reply or Sign up for a free account.