Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Insomniac on July 11, 2009, 02:33:37 am

Title: Compiler Problem?
Post by: Insomniac on July 11, 2009, 02:33:37 am
Sorry if this is in the wrong forum.

Anyways, I have this code (very basic:)

Code
#include <iostream>

int test = 1;

if(int == 1) {
    cout << "this is a good test." << endl;
} else {
    cout << "this is not a good test." << endl;
}

And I am getting these errors:

Code
C:\Users\John\Documents\CPP\Winsock\bla.cpp|5|error: expected unqualified-id before "if"|
C:\Users\John\Documents\CPP\Winsock\bla.cpp|7|error: expected unqualified-id before "else"|
||=== Build finished: 2 errors, 0 warnings ===|

It's still there even if I add a "using namespace std;"

I'm really confused. Any help would be GREAT!
Title: Re: Compiler Problem?
Post by: plee3 on July 11, 2009, 06:03:48 am
Although CodeBlocks is an IDE and not a compiler, your problem is that your code is not a compilable program. There are numerous errors:

1) There is no function declaration for your program. You need to define a "main" function to place your "if" code.
2) You cannot test "if (int == 1)" as int is not a variable but a type name.

Please read more examples of C++ from online tutorials or books and good luck in learning more about programming.

Title: Re: Compiler Problem?
Post by: Jenna on July 11, 2009, 08:55:10 am
The topic is absolutely unrelated to C::B, therefore it gets locked !