i have a header file which contains a random number generator
here is the code:
#include <cstdlib>
#include <time.h>
#ifndef RANDOM_H
struct rand_var{
int x,y;
}Rand_var;
static int rand_gen()
{
srand ((unsigned)time(NULL));
extern int random;
random = rand() % (Rand_var.x-Rand_var.y+1) + Rand_var.x;
}
#endif /* random.h */
you will probably com-plain about the struct, and that i should just put the declaration in the static int, or just not in there at all.
anyways, the problem i'm having is when i try to intialize it in this code:
#include <iostream>
#include <Windows.h>
#include <conio.h>
#include "random.h"
struct enemies
{
bool alway_app;
bool cote_app;
bool alexF_app;
}enemy;
using namespace std;
int main()
{
extern int random;
int i;
do
{
for(i = 0; i>=100; random)
if (i == 1 || i == 2 || i == 3)
break;
else continue;
}while(i = 0);
if (i == 1)
enemy.alway_app = true;
else if (i == 2)
enemy.cote_app = true;
else enemy.alexF_app = true;
if(enemy.alway_app = true)
cout << "Kaleb Alway Appeared!\n\n";
if(enemy.cote_app = true)
cout << "Dylan Cote Has Appeared\n\n";
if(enemy.alexF_app = true)
cout << "Alex Frankland has appeared\n\n";
cout << random << "\n\n";
cout << random << "\n\n";
Sleep(0500);
return 0;
}
it keeps on giving me LNK2001 and LNK1120 errors where it says "EXTERN INT RANDOM". so i must have declared them wrong.
anyways, how do i declare it properly?