This wont compile correctly, it says "implicit declaration of function `int random(...)'"
Code:#include <stdio.h>
#include <math.h>
#include <iostream.h>
int main()
{
int topf;
topf=random(5);
cout<<topf;
return 0;
}
Printable View
This wont compile correctly, it says "implicit declaration of function `int random(...)'"
Code:#include <stdio.h>
#include <math.h>
#include <iostream.h>
int main()
{
int topf;
topf=random(5);
cout<<topf;
return 0;
}
there is no function called random()
Those headers are deprecated in c++ use c++ headers
math.h is unused.
At least the int main is correct.:)
That means you have a function that hasn't been defined but is still used in your program. In this case, the function is named random. As far as I know, there isn't a function with that name anywhere. I assume that you want a random number between one and five yes? This is how you do that:
Code:topf=rand()%5+1;
Thanks ill try that, Stoned_coder, some of the header files arent used because the prog isnt done. :)
EDIT: I got the same error using the other code
Code:topf=rand()%5+1;
Oops, my bad. Make sure you have this line after your #include's:
Code:using namespace std;
In C rand() lives in the header stdlib.h
In C++ std::rand() lives in the header cstdlib
And you should make a call to the srand() function prior to using rand(). That provides a "seed" for the random number. The results from the time function are a good one. For time you will need to include the ctime header which is the equivalent of c's time.h.
Code:#include <iostream>
#include <ctime>
using namespace std;
int main(void)
{
srand(time(NULL)); // Only call me ONCE
// Do stuff like call rand()
return 0;
}