Author Topic: Compiler Problem?  (Read 3529 times)

Offline Insomniac

  • Single posting newcomer
  • *
  • Posts: 3
Compiler Problem?
« 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!

Offline plee3

  • Single posting newcomer
  • *
  • Posts: 4
Re: Compiler Problem?
« Reply #1 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.


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Compiler Problem?
« Reply #2 on: July 11, 2009, 08:55:10 am »
The topic is absolutely unrelated to C::B, therefore it gets locked !