//file included from main.cpp
#include <iostream>
#include <ctime>

void generate(int height, int width)
{
    int i,j,random,x,y,check;
    char map[height][width];
    bool way[4], border[3];

    srand(time(NULL)); //[error 'srand' was not declared in this scope]

    for(i=0; i<height; i++)
    {
        for(j=0; j<width; j++)
            map[i][j] = 178;
    }

    x = rand()%height; //[error: 'rand' was not declared in this scope]
    y = rand()%width; //[error: 'rand' was not declared in this scope]
    map[x][y] = 'x';
   //...
}

This file is included from main.cpp. When this function was in main file there wasn't any trouble. I tried to use headers and split main to:
main.cpp
header.h
funct.cpp

What's wrong in this?

Recommended Answers

Put the srand() functionn call back in main() .

And where's the header that define the random functions?

Jump to Post

All 2 Replies

Put the srand() functionn call back in main() .

And where's the header that define the random functions?

srand is in cstdlib. So try to include cstdlib.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.