Modules problem

Hi, i am very new to C++ programming and i'm really keen to learn. However, i've run into a problem and it's stressing me out! i've googled and searched this forum but cannot find a solution. i did find someone with a similar problem but their fix didn't fix mine.

anyway, here is the code and the error i'm getting when trying to compile.

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
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

#include "factorial.h"


int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "This Program calculates factorials"
        << " of user input.\n"
        << "Enter a negative number to exit" << endl;

        for (;;)
        {
            int nValue;

            cout << "Enter Number: ";
            cin >> nValue;

            if (nValue < 0)
            {
                break;
            }

            int nFactorial = factorial(nValue);
            cout << nValue << " factorial is "
                << nFactorial << endl;
        }

    system("pause");
    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdio>
#include <cstdlid>
#include <iostream>

using namespace std;

#include "factorial"

int factorial(in nTarget)
{
    int nAccumulator = 1;
    for (int nValue = 1; nValue <= nTarget; nValue++)
    {
        nAccumulator *= nValue;
    }

    return nAccumulator;

}


1
2
3
4
5
6
#ifndef FACTORIAL_H_INCLUDED
#define FACTORIAL_H_INCLUDED

int factorial(int nTarget);

#endif // FACTORIAL_H_INCLUDED 


And here is the error i'm getting.

G:\c++\Projects\FactorialModule\main.cpp||In function 'int main(int, char**)':|
G:\c++\Projects\FactorialModule\main.cpp|28|error: 'factorial' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|


many many thanks to anyone that can help me with this. it's making my brain hurt!!

Royal
Last edited on
#include "factorial.h"

#include "factorial"
?
int factorial(in nTarget) What?
Last edited on
I don't understand where i've gone wrong :/

Is what i've written complete gibberish??
ah ok, so i've changed them both to factorial.h now and changed ín' to ínt'.

still get the same error.
Did you add the second file to your project?
EDIT:
I suppose not: it should give you a shitload of compile errors.
What IDE do you use?
Last edited on
Topic archived. No new replies allowed.