User forums > Using Code::Blocks

Compiler Problem?

(1/1)

Insomniac:
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;
}
--- End code ---

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 ===|
--- End code ---

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

I'm really confused. Any help would be GREAT!

plee3:
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.

Jenna:
The topic is absolutely unrelated to C::B, therefore it gets locked !

Navigation

[0] Message Index

Go to full version