Dev C++ - including header files

Hi,

I have made my class interface and saved it as "Factorial.h". I have then written the class implementation and saved it as a .cpp file. In the .cpp file I am trying to include my header file but I am getting the message "no such file or directory. I believe it is because I am not telling the IDE where the file is but I am unsure how to do that.

Am I doing it correctly and how do I tell the IDE where to find the .h file?

***My IDE is Dev C++***

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//This is my header file which is saved as Factorial.h
//Author:       **********
//Date: 	25/11/2013
//Title:        Class Factorial
//Description:  Class that calculates fatcorial using the number inputted by user

#include <iostream>//not sure if this is needed?

using namespace std;//not sure if this is needed?

class Factorial
{
     public://begin public section
            unsigned int get_number();//accessor member function
            void set_number();//accessor member function
            unsigned int get_value ();
            void set_value ();
     private://begin private section
            unsigned int its_number;//member variable
            unsigned int its_value;//member variable
};

===================================================================
//This is my program which includes the class implementation
#include <iostream>
#include <conio.h>
#include "Factorial.h"

//Public accessor function which returns value of its_number member
unsigned int Factorial::get_number()
{
     return its_number;//returns value of member variable its_number
}

//Public accessor function which sets value of its_number member
void Factorial::set_number()
{
     cout << "Enter your number: ";//user prompted to enter number
     unsigned int number;
     cin >> number;
     its_number = number;//setting value of member variable its_number
}

//Public accessor function which returns value of its_value member
unsigned int Factorial::get_value()
{
     return its_value;
}

//Public accessor function which is used to set value for "its_value"
void Factorial::set_value ()
{
     if (its_number == 1 || its_number == 0)
        its_value = 1;
     else
     {
         unsigned int value = its_number;//declaring variable value that holds the value of the calculated factorial.
         unsigned int count = its_number;//count used to replace its_number as we don't want to change the value
         for (count; count > 1; count--)
         {
             value *= (count-1);//calculating factorial 
         }
         its_value = value;//setting value for its_value
     }
}

int main ()
{
    Factorial myFactorial;//creating object of class Factorial
    myFactorial.set_number();//calling member function to set value of member variable its_number
    myFactorial.set_value ();//calling member function to set value of member variable its_value
    cout << myFactorial.get_number() << "! is " << myFactorial.get_value() << endl;
    
    _getch ();//pauses program
    return 0;
}
Well I now know that my header file is working and my problem is due to the path.

I just moved my header file to where the standard libraries are contained and my program compiled and produced the expected output.

However, I would like to keep my classes in a separate location. Does anyone know how I tell Dev C++ where to find my header files?
Topic archived. No new replies allowed.