First off, you should know I just started learning C++ today.
Anyway, whenever I type in my code to Dev_C++ Compiler, and then try to run it, it always says "Source file not completed." Here's my code:

// operating with variables

#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 5;
  b = 2;
  a = a + 1;
  result = a - b;

  // print out the result:
  cout << result;

  // terminate the program:
  return 0;
}

Why won't it work?

I'm also using Dev-c++ and I used your code. Works fine for me. You just need to add in a

system("PAUSE");

before your return 0;

That way it leaves the window open allowing you to see a result.

Sorry but i must say that's completly wrong.
First of all don't use system("pause"), use cin.get().
Secondly, make sure that you have a project of the type console project open and make sure you source code file(.cpp) is associated with that project.

If you have troubles check this image http://www.bloodshed.net/images/devcpp_scr.jpg.
To the left it says Jackpot(the project) and below it it's says main.
Your window should look similar.

Sorry but i must say that's completly wrong.

I see nothing wrong with...

system("PAUSE");

In fact, the default c++ code Dev-C++ produces from its default console template uses it. Are you saying the folks who wrote the Dev-C++ IDE don't know what they are doing?

Personally, I usually don't use a lot of the default C++ headers in my console programs and use the C ones instead. I usually hold the screen open with getchar() from stdio.h.

There is nothing wrong with system("pause"), it works great, but it has several downsides compared to cin.get() and others.
1. It prints loads of ugly code when used.
2. It's sometimes picked up as a virus in ceartin anti virus softwares.

Therefor cin.get() is superior.

//k0ns3rv

Does leaving the window open actually answer the question of the error message IndyColt is generating? I think that maybe K0ns3rv actually came closest to answering the question!

However, the other information is valuable. IndyColt, do you understand why you would use the code advice given above to keep the window open? If not, anytime a function is set to "return,' it hands operations back to the calling program. For example, when you tell a program to print, the print menu doesn't just stay open until you shut your computer down. Once, it has filled it's job, it closes. The signal for the print menu to close (return) is a user response, but when you write your own functions, they don't necessarily have to wait for a user response.

Also, notice that you returned a 0. That means that the calling function isn't asking for any information back from your function. The results are printed on the screen for the human to see and then it's done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.