Question about seperate files

Started by
21 comments, last by Chad Smith 17 years, 8 months ago
I made a header file named Globals.h to put all my global variables in and declare my functions. Well when I compile it useing bloodshed it gives me: Globals.h no such file and then says my variables arent being declaired.

// MAIN

#include <iostream>
#include "Globals.h"
using namespace std;

int playercharacter();
int PName();  
int Gender(); 
int Race();
int Profession();
int Human();
int Elf();
int Dwarf();
int Warrior();
int Wizard();
int Cleric();


int main()
{
    bool charactersetup = false;
    if(charactersetup == false)
    {
        cout << " Welcome to Kesmere\n\n\n ";
        PName();
        Gender();
        Race();
        Profession();
        charactersetup = true;
    }    
    else
    {
    }    

    system("pause");

    return 0;
}

int PName()
{
    char name[50];

    cout << " Enter your name\n\n";
    cin >> name;
    cout << " You have chosen to be known as " << name << ".\n\n";
}  

int Gender()
{
    int gender;
    string gendername;
    cout << " Please choose your gender\n";
    cout << "1. Male" << endl;
    cout << "2. Female\n\n";  
    cin >> gender;
    if(gender == 1)
    {
        gendername = "male";
        cout << "You have chosen to play as a " << gendername << endl;
        
        
    }
    else
    {
        gendername = "female";
        cout << "You have chosen to play as a " << gendername << "\n\n";
    }       
    
}    

int Race()
{
    int rchoice;
    
    cout << " Please chose:\n";
    cout << " 1. human " << endl;
    cout << " 2. elf " << endl;
    cout << " 3. dwarf " << endl;
    cin >> rchoice;
    
    switch(rchoice)
    {
        case 1:
            Human(); 
            break;
        case 2:
            Elf(); 
            break;
        case 3:
            Dwarf(); 
            break;    
    }    
    
}    

int Profession()
{
    int pchoice;
    
    cout << " Please chose:\n";
    cout << " 1. warrior " << endl;
    cout << " 2. wizard " << endl;
    cout << " 3. cleric " << endl;
    cin >> pchoice;
    
    switch(pchoice)
    {
        case 1:
            Warrior(); 
            break;
        case 2:
            Wizard(); 
            break;
        case 3:
            Cleric(); 
            break;    
    }    
    
}    



int Human()
{
    string race = " human ";
    hp = 10;
    dex = 8;
    mana = 6;
    
    cout << "You have chosen to play as a" << race << "." << "\n\n";
    cout << " You now have:" << endl;
    cout << " Hit Points: " << hp << endl;
    cout << " Dexterity: " << dex << endl;
    cout << " Mana: " << mana << "\n\n";
}    

int Elf()
{
    string race = " elf ";
    hp = 9;
    dex = 7;
    mana = 10;
    cout << "You have chosen to play as a" << race << "." << "\n\n";
    cout << " You now have:" << endl;
    cout << " Hit Points: " << hp << endl;
    cout << " Dexterity: " << dex << endl;
    cout << " Mana: " << mana << "\n\n";
} 

int Dwarf()
{
    string race = " dwarf ";
    hp = 12;
    dex = 9;
    mana = 5;
    cout << "You have chosen to play as a" << race << "." << "\n\n";
    cout << " You now have:" << endl;
    cout << " Hit Points: " << hp << endl;
    cout << " Dexterity: " << dex << endl;
    cout << " Mana: " << mana << "\n\n";
} 

int Warrior()
{
    string profession = " warrior ";
    cout << "You have chosen to play as a" << profession << "\n\n";
}    

int Wizard()
{
    string profession = " wizard ";
    cout << "You have chosen to play as a" << profession << "\n\n";
}

int Cleric()
{
    string profession = " cleric ";
    cout << "You have chosen to play as a" << profession << "\n\n";
}        

and here is my global.h code

#include <iostream>
using namespace std;

int hp;
int dex;
int mana;
Advertisement
Do you have a file named Globals.h, as opposed to global.h ?
The global.h file is in my project file.
Thanks
It is Globals.h and I am using Globals.h with the capital G
Thanks
The error message can only mean two things:
  • The file is not present in the same directory as the including file
  • The file is present, but cannot be read

    Therefore, I can only suggest that you check the existence of the two files, and the access rights for the header file.
  • Let me see if I can find this article about organizing code files in C++. Mmmm...


    FOUND IT

    Organizing code files in C/C++

    Hope that helps!

    Chad.
    With an 's' at the end, or without? Thus far you've said both "Globals.h" and "global.h".
    "We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
    Globals.h
    I will look at that article.
    Thanks
    Ok, I reads the article it was hepful, but I didnt understand a few things. unfortunatly I'm having the same problem. I tried useing ms visual and it worked fine, but it wont work on bloodshed. :/
    Mmm...it won't work in Dev, but it will in Visual? That seems weird.


    Why don't you just use Visual then? IMO it is a lot better IDE, and it has a very nice Debugger.


    Chad.

    This topic is closed to new replies.

    Advertisement