Results 1 to 8 of 8
  1. #1
    -:TKK:-WaSsUp's Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    27
    Reputation
    10
    Thanks
    14

    Post C++, Making a Console Application

    Downloads you need:
    Code::Blocks
    or
    Bloodshed Software - Dev-C++

    Creating a Project.

    The first step to creating a C++ program is to create what is known as a project. A project tells Code::Blocks the names of the .CPP source files to include ans what type of program to create. Most of the programs in the book will consist of a single source file and will be command-line style:

    1. Choose Start→Programs→CodeBlocks→CodeBlocks to start up the CodeBlocks tool.

    2. From within Code::Blocks, choose File→New→Project.

    3. Select the Console Application icon and then click Go.

    4. Select C++ as the language you want to use from the next window Click Next.
    Code::Blocks and gcc also support plain ol' C programs.

    5. Select the Console Application icon and then click Go.

    6. In the Folder to Build Project In the field, navigate to the subdirectory where you want your program built.

    7. In the Project Title field, type the name of the project, in this case name it "Conversion"
    The resulting screen is shown below.


    8. Click Next
    The next window gives you the option of creating an application for testing or the final version. The default is fine.

    9. Click Finish to Create the conversion project.

    Entering the C++ code

    The Conversion project that Code::Blocks creates consists of a single, default main.cpp file that does nothing. The next step is to enter our Program:

    1. In the management window on the left, double-click main, which is under Sources, which is under Conversion.
    Code::Blocks opens the empty main.cpp program that it created in the code editor as shown in the picture below.


    2. Edit main.cpp with the following program exactly as written.
    Don't worry too much about the indentation or spacing - it isn't critical whether a given line is indented two or three spaces, or whether there are one or two spaces between two words. C++ is case sensitive, however, so you need to make sure everything is lowercase.

    Code:
    //
    // conversion - program to convert temperature
    //            Celsius degrees into Fahrenheit:
    //            Fahrenheit = Celsius * (212 - 32)/100 + 32
    //
    #include <cstdio>
    
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
      // enter the temperature in Celsius
      int celsius;
      cout << "Enter the temperature in Celsius:";
      cin >> celsius;
    
      // calculate conversion factor for celsius
      // to Fahrenheit
      int factor;
      factor = 212 - 32;
    
      // use conversion factor to convert Celsius
      // into Fahrenheit values
      int fahrenheit;
      fahrenheit = factor * celsius/100 + 32;
    
      // output the results (followed by a NewLine)
      cout << "Fahrenheit value is:";
      cout << fahrenheit << endl;
    
      // wait until user is ready before terminating program
      // to allow the user to see the program results
      system("PAUSE");
      return 0;
    }
    3. Choose File→Save to save the source file.
    I know that it may not seem all that exciting, but you've just created your first C++ Program!

    Building Your Program

    After you've saved your C++ source file to disk, it's time to generate the executable machine instructions.

    To build your Conversion program, you choose Build→Build from the menu or press Ctrl-F9. Almost immediately, Code::Blocks takes off, compiling your program with gusto. If all goes well, the happy result of 0 errors, 0 warnings appears in the lower right window.

    Code::Blocks generates a message if it finds any type of error in your C++ program - and coding errors are about as common as ice cubes in Alaska. You'll undoubtedly encounter numerous warnings and error messages, probably even when entering the simple Conversion.cpp. To demonstrate the error-reporting process, let's change lin 16 from cin >> celsius; to cin >>> celsius;.

    This seems an innocent enough offense - forgivable to you and me perhaps, but not to C++. Choose Build→Build to start the compile and build process. Code::Blocks almost immediately places a red square next to the erroneous line as shown in the picture below. The message in the Build Message tab is rather cryptic error: expected primary-expression before '>' token. To get rid of the message, remove the extra '>' and recompile.

    Tip: You probably consider the error message generated by the example a little cryptic but give it time - you've been programminf for only about 30minutes now. Over time you'll come to understand the error messages generated by Code::Blocks and the gcc much better.

    Warning!: Code::Blocks was able to point directly at the error this time but it isn't always that good. Sometimes it doesn't notice the error until the next line or the one after that, so if the line flagged with error looks okay, start looking at its predecessor to see if the error is there.

    Executing your program

    It's now time to execute your new creation...that is, to run your program. You will run the CONVERT.EXE program file and give it input to see how well it works.

    To execute the Conversion program, choose Build→Build and Run or press F9. This rebuilds the program if anything has changed and executes the program if the build is successful.

    A window opens immediately, requesting a temperature in Celsius. Enter a known temperature, such as 100 degrees. After you press Enter, the program returns with the equivalent temperature of 212 degrees Fahrenheit as follows:
    Code:
    Enter the temperature in Celsius:100
    Fahrenheit value is:212
    Press any key to continue . . .
    The message Press any key to continue . . . gives you the opportunity to read what you've entered before it goes away. Press Enter, and the window (along with its contents) disappears. Congratulations! You just entered, built, and executed your first C++ program.


    Credits:
    C++ for Dummies 6th Edition for this.
    -:TKK:-WaSsUp for typing all of this.
    Last edited by -:TKK:-WaSsUp; 10-25-2010 at 08:52 PM.

  2. #2
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Time spent doing this is appreciated but there are better sources for learning the basics of programming. For one, you can buy/download the book for yourself or look up free tutorials/references which cover almost all the basics.

  3. The Following 2 Users Say Thank You to Void For This Useful Post:

    Hell_Demon (10-26-2010),xTremist (10-29-2010)

  4. #3
    -Raz0r-'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Australia
    Posts
    117
    Reputation
    15
    Thanks
    38
    My Mood
    Lurking
    And you had to choose the lesser-used/supported/featured IDE's why..?
    Also C++ as a first language
    Languages: C, C++, x86 ASM, PHP, Lua

  5. #4
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Dev-C++ has not been maintained for over 5 years. Why still use it for?

  6. #5
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    Quote Originally Posted by freedompeace View Post
    Dev-C++ has not been maintained for over 5 years. Why still use it for?
    Maybe he wants an IDE that doesn't take as much resource as visual studio does.

    VC++ 2010 takes 10 seconds to compile even the simplest of programs on my PC.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




  7. #6
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by Kallisti View Post


    Maybe he wants an IDE that doesn't take as much resource as visual studio does.

    VC++ 2010 takes 10 seconds to compile even the simplest of programs on my PC.
    VC++ 2010 is shit...
    2003 .net is god, 2008 is okay
    Ah we-a blaze the fyah, make it bun dem!

  8. #7
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by Kallisti View Post


    Maybe he wants an IDE that doesn't take as much resource as visual studio does.

    VC++ 2010 takes 10 seconds to compile even the simplest of programs on my PC.
    If he wants that, there are numerous alternatives that are current and are under active development.

  9. #8
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    Quote Originally Posted by freedompeace View Post
    If he wants that, there are numerous alternatives that are current and are under active development.
    It's still preference. DevC++ isn't that bad tbh.

    I like how they have DevPaks though. Just load it with DevC++ and it sets up all the APIs includes, libs, etc

    I don't use it anymore though.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




Similar Threads

  1. Possble to make a console with built in alias command?
    By sfcrazy in forum Vindictus Discussions
    Replies: 5
    Last Post: 08-11-2011, 11:51 AM
  2. [Release] PlayTheGame ~ The console application!
    By VvITylerIvV in forum C++/C Programming
    Replies: 9
    Last Post: 06-03-2011, 09:20 AM
  3. [TuT] You First C++ Console Application
    By sam22 in forum Programming Tutorials
    Replies: 6
    Last Post: 11-30-2010, 07:56 PM
  4. C++ console application
    By VvITylerIvV in forum C++/C Programming
    Replies: 39
    Last Post: 08-04-2010, 05:08 AM
  5. What's the point of Console applications?
    By 258456 in forum C++/C Programming
    Replies: 2
    Last Post: 06-05-2010, 03:22 PM