LightbulbVariables

Posts 1–3 of 3 · Page 1 of 1
Variables
Well I need to know how to use variables of other parts like..

Code:
int table () {
	int bad1 = rand() % 8 + 1;
	int bad2 = rand() % 8 + 1;
	int bad3 = rand() % 8 + 1;
	game ();
}
This is where the variables are and then I need to use the value of that variables in another part like..
Code:
	int game () {
		badl1 = bad1;
		badl2 = bad2;
		badl3 = bad3;

}
But i get error that the variables are not defined... ani solution?
someone else will eventually explain that to you. But, read a fucking book and follow a tutorial. God... thats basic questions that anywhere on the Internet will be answered.
Nope. You can't do it like that. Make a class, place bad1,bad2 and bad3 just below the class, so it is available to all the functions of the class. Then set the them as appropriate:

[highlight=c++]class Crap
{
private:
int bad1;
int bad2;
int bad3;
public:
int table () {
bad1 = rand() % 8 + 1;
bad2 = rand() % 8 + 1;
bad3 = rand() % 8 + 1;
return game ();

};
int game () {
int badl1 = bad1;
int badl2 = bad2;
int badl3 = bad3;
return 0;
};
};[/highlight]

Use it like this:

[highlight=c++]void main()
{
Crap c;
c.table();
}[/highlight]
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us