News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Compiler Problem?

Started by Insomniac, July 11, 2009, 02:33:37 AM

Previous topic - Next topic

Insomniac

Sorry if this is in the wrong forum.

Anyways, I have this code (very basic:)

#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:

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!

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 !