Trouble with Practice Code

Apr 17, 2013 at 7:12pm
I've been reading this very well written beginner's C++ book which has been helping me tremendously. One problem. The code below is not working. All it should do is output:
0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
3,0 3,1 3,2
4,0 4,1 4,2

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

using namespace std;

int main()
{
    const int ROWS = 5;
    const int COLUMNS = 3;
    
    for (int i = 0; i < ROWS; ++i)
    {
        for (int j = 0; j < COLUMNS; ++j)
        {
            cout << i << "," << j << " ";
        }
        
        cout << endl;
    }
    
return 0;
}


The compiler comes up with these errors:


/tmp/ccQgPNB9.o
null
null
In function `main':

NumberGuess.cpp
null
null
(.text+0x0): multiple definition of `main'

/tmp/ccPA6bbf.o
null
null
ForStatements.cpp:(.text+0x0): first defined here

collect2
null
null
ld returned 1 exit status


The first 3 are warnings and the last is "illegal"

I would really appreciate your help.
Apr 17, 2013 at 7:18pm
It looks like you are trying to compile several modules.
What are NumberGuess.cpp, ForStatements.cpp and so on?
Apr 17, 2013 at 7:22pm
Oh ok. Oops. I created a new file in the same source code folder as my last practice file. That would be the cause then?
Apr 17, 2013 at 7:25pm
Yup, that fixed it. Well, guess you learn extra stuff from human error on the side from learning the book.
Topic archived. No new replies allowed.