I am writing a basic game program to use as a reference later on. BUT if I try to use teh same variable in both it says multiple definitions, and if I dont init the variable it wont either. Here is what I am trying to do...
FIRST .CPP
and just a test .cpp looks like this.Code:#include "main.h" #include "colors.h" int a; void mainmenu(); void charmenu(); int EXIT(); void options(); void newgame(); void loadgame(); // int main() { mainmenu(); return 1; } void mainmenu() { text_red; system("cls"); cout << "****************\n"; cout << "*(1) New Game *\n"; cout << "*(2) Load Game *\n"; cout << "*(3) Options *\n"; cout << "*(4) Exit *\n"; cout << "****************\n"; text_darkgrey; cout << "Selection: "; cin >> a; cin.ignore(); switch ( a ) { case 1: newgame(); break; case 2: break; case 3: break; case 4: EXIT(); break; default: cout <<" Sorry but Please Input 1-4 please"; cout <<" Press ENTER to continue"; cin.get(); mainmenu(); break; } } // int EXIT() { system("cls"); cout.flush(); return (EXIT_SUCCESS); } //END OF EXIT
now the errors areCode:#include "main.h" int a; //the following are the diffrent programs within the mother program to make this game playable void mainmenu(); void charmenu(); int EXIT(); void options(); void newgame(); void loadgame(); //end of menu setup//notice ALL menus except main and Exit are void void newgame() { cout << "New Game Test Cout Function"; cin.get(); cin >>a; cin.ignore(); cout <<"Test 2 you entered "<< a <<" as a number"; cin.get(); }
I have tried not difing it in the newgame .cpp but it wont and defing it i get errors as well so what is wrong.Code:multiple definition of `a' first defined here ld returned 1 exit status