webspace hosting reseller hosting|             | blog| forum| dating| free hosting| openhost| report abuse
Internet Fax To Email - Unlimited

Unlimited Faxes, No Fees, Dedicated Phone Number

Free Website Templates

The C++ Programming Adventure!


Join the Fun!

Session 2: Some Real C++

Well, you finally made it here. Hopefully, in the last session you learned a little C++. Now, you can show stuff on a screen. How exciting. You can impress your friends with a very fun game called staring at console text! However, that's not a great way to inspire awe, so it's time to learn a little more. In order to achieve greatness, though, you need the tools of a programmer. So, before you learn any more C++, it's time to learn Dev-C++.

Dev-C++ is not a separate language; it is an IDE, or Integrated Development Environment. Basically, it's a mix of several important utilities you need when making programs:

With Dev-C++, it's much easier to create C++ programs because this IDE handles most of the details for you. All you have to do is feed it C++ code. It will help you compile your program, debug it, and fix errors. As you'll soon find, Dev-C++ is a very useful tool for programming.

However, Dev-C++ is not the only IDE out there. In fact, I recommend that you try Microsoft Visual C++ if possible. There should only be some minor differences between Microsoft's compiler and MinGW (comes with Dev-C++). However, Visual C++ is much more powerful and easy-to-use. And, as an added bonus, Dev-C++ can open Visual C++ files. You can download Visual Studio .NET Express from Microsoft, which includes Visual C++. You will need Windows 2000 or XP to use it. However, you're on your own if any problems come up; I can't help you because I can't run Visual C++. Even so, it's still a good IDE to try.

Setting Up Dev-C++

Dev-C++ is freely available from The Dev-C++ Resource Site. It requires a Windows PC, and can run on pretty crappy computers (believe me, I know). To get it, try clicking here. If that doesn't work, click here. The download shouldn't take long.

After the Download

  1. Open it. You should encounter the Dev-C++ install program.
  2. Accept all of the regular setup options, if possible. Please at least keep the regular install directory.
  3. Open Dev-C++, which can be found in the Windows Start menu, on the desktop, or in the Quick Launch bar.
  4. Accept the default setup options if Dev-C++ asks, unless you know what you're doing.
  5. Congratulations! You shoud come up with a blank Dev-C++ screen.

Your First Project

Now that you're in Dev-C++, you're ready to create a project. You won't be doing much; you'll basically make a program that says "Press any key to continue . . .". It will only have that "standard stuff" we've been working with so far. Don't change the code; that's for later! For now, click here.

Dev-C++ with some code.

Once you're done with that, you have a Dev-C++ window with code in it. You can edit this code just as you edit a document in a word processor. Dev-C++ will highlight C++ keywords as you type, and will (hopefully) automatically indent each line. You may add cout commands from Session 1 after the opening brace ({) after "int main", and before system("PAUSE"). Then, see the directions for compiling below. Here's a summary of commands you know:

General Rules

  • Each piece of data is separated by <<.
  • Each statement, which is a complete command, ends with a semicolon (;)

The cout statement

cout << endl << "Hello, Aliens! My SSN is " << 11235813 <<
    ", and 15 + 1568 is" << 15 + 1568 << ".";
  • Strings are bits of text enclosed by double-quotes. They can contain any letter, number, punctuation symbol or wild gorilla inside with one rule: there can only be two double-quotes: one at the beginning, and one at the end..
  • Numbers are just that -- numbers! They do not have quotes around them. The computer sees them and can use them as numbers. However, since computers are limited, please don't enter more than 12 digits.
  • Expressions -- remember these from algebra? You can input basic mathematical expressions involving several operations, including:
    • + Addition
    • - Subtraction
    • * Multiplication
    • \ Division (cuts off the fraction part)
    • % Remainder (like division, but tells you the remainder instead)
  • endl ends a line.

Compiling and Running Your Project

To compile, you can either select Compile from the Project menu or click the Compile button (from the tutorial). However, the compiler will only compile code that follows the C++ rules. If you forgot a rule, the compiler gives you an error message -- and stops compiling your program. This error is called a compile-time error, because it happens even before your program starts. You must remove all of these errors before your program will start.

Dev-C++ Error

If your program had mistakes, you won't see Done in the Compile Progress window. Instead, Dev-C++ will highlight your first mistake and show a list of mistakes at the bottom. Here's a few possible errors and their fixes:
Error MessageErrorFix
expected ';' You forgot to end a statement with a semicolon, or you left out a << somewhere. Put a semicolon at the end of the statement without one, or insert the << where it belongs.
missing terminating " character You don't have a double-quote at both ends of a string, or you have double-quotes in between. Make sure there's only two double-quotes: one at the beginning, and one at the end.
expected primary-expression before '<<' token. You forgot to begin a cout statement with cout, or you have a semicolon before the end of your statement. Make sure all your bits of information are between cout and the semicolon.

Your Quest: "It Came from the Console"


Create a working program that displays a message of your choice. This message should contain each of the possible parts of a cout statement. When you're done, you should send an e-mail to me, where you either...

  • ...copy and paste your code into the message.
  • ...attach your main.cpp code file, which would be in C:\ProgCode\My First Project\ if you followed the lesson.
  • If you need help, be sure to e-mail me your questions. Good luck!