When you #include something, the preprocessor copies it exactly into where you put it. So everywhere that you #include "globals.h", you are pasting this:
1 2 3 4 5 6 7 8 9 10
class globals
{
public:
globals();
};
int PlayerChoice, e, E;
char UserName[12];
Thus, every cpp file you #include "globals.h" in has
1 2
int PlayerChoice, e, E;
char UserName[12];
pasted into it.
Where's the extern? Nowhere. So you've got this:
1 2
int PlayerChoice, e, E;
char UserName[12];
in every cpp file at the global level. Which means you've tried to define the same objects over and over again, which is exactly what you were doing at the start.
#include <iostream>
#include <string>
#include "inn.h"
#include "store.h"
usingnamespace std;
int PlayerChoice, e, E;
char UserName[12];
int main()
{
cout << "Welcome to Cinz\n";
cout << "What would you like to do?\n";
cout << "1) Play\n";
cout << "E) Exit\n";
cin >> PlayerChoice;
if(PlayerChoice == 1)
{
cout << "Many years ago when I was child my dad left he told me keep your mother safe I will be back tomorrow. I sat there at the window for days just waiting for him to return. Everytime I fell asleep all I could see was his face fading away from my eyes. It had been years before I let him go. Now everytime I here his name Rale. My body builds up constant rage. Now that he is gone I have set out to avenge her.\n\n";
cout << "What is your name: ";
cin >> UserName;
cout << "Hello " << UserName << " What would you like to do?\n\n";
cout << "1) Go to inn\n";
cout << "2) Go to Store\n";
cout << "3) Go exploring\n";
cout << "4) Character page\n";
cout << "5) Inventory page\n";
cout << "E) Exit Program\n";
cin >> PlayerChoice;
}
if(PlayerChoice == 1)
{
Inn go;
}
elseif(PlayerChoice == 2){
Store go;
}
elseif(PlayerChoice == E || e)
{
return 0;
}
return 0;
}
#include "inn.h"
#include <iostream>
usingnamespace std;
externint PlayerChoice, e, E;
externchar UserName[12];
Inn::Inn()
{
do{
cout << "Welcome to the Inn How may I be of service today?\n";
cout << "1) Rest\n";
cout << "E) Exit the inn\n";
cin >> PlayerChoice;
cout << UserName << "you are now well rested\n\n";
}
while(PlayerChoice == 1);
if(PlayerChoice == E || e){
}
}
inn.h
1 2 3 4 5 6 7 8 9 10 11
#ifndef INN_H
#define INN_H
class Inn
{
public:
Inn();
};
#endif
yeah I know the way you did it works. but, I was trying to declare it once in 1 file and have it be able to use in all the rest. thats why I made globals.h