954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with a header file

Can somebody please tell me what am I doing wrong?
I have created a so called "game" and I have decided to add some random events. That's where I got this nasty error which I do not know how to dispose of.

#ifndef FUNC_H
#define FUNC_H

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

 srand /*HERE IS THE ERROR*/( time(NULL) );
 int random_event_number = (rand()%100)+1;


ERROR :
func.h:10:7: error: expected constructor, destructor, or type conversion before '(' token

EXTRA INFO : I am using Linux OS, Vim text editor and g++ compiler.
Here are the files of my game: http://www.2shared.com/file/0cKHjMcI/func.html
http://www.2shared.com/file/zrokTSml/average_life.html

You have helped me before and I know you can help me with this one too :)
Thanks!

Triarius
Newbie Poster
8 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

You can't have executable code outside of a function body. Move those parts to main():

int random_event_number;

int main()
{
    srand(time(NULL));

    random_event_number = rand() % 100 + 1;

    ....
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: