C++C++11C++14C++17C++20Introduction to C++Language FeatureLearn C++

Five Simple C++ Console Examples for Beginners

Five Simple C++ Console Examples for Beginners

The C++ Builder CE Community Edition is a free version of professional C++ Builder that you can develop GUI based desktop and mobile applications in C++. In this post, we will give you five simple C++ console examples for beginners you can run using C++ Builder 11 CE.

Five Simple C++ Console Examples for Beginners the CE Edition splash screen

The latest C++ Builder 11 CE was released in April 2023. If you are a start-up developer, student, hobbyist or just interested in learning to code then C++ Builder Community Edition may well be just the thing for you. Read the FAQ notes on the CE license and then simply fill out the form and download C++ Builder 11 CE.

How to develop a C++ console application in C++Builder CE?

If you download C++ Builder Community Edition then we can start to coding,

  1. Create a new C++ Builder Console application from File->New-> menu
  2. In the New Console Application window leave Target Framework blank “None”
  3. Be sure that Source Type is C++ and press OK
Five Simple C++ Console Examples for Beginners choosing the framework

This will open a new code editor window at the center.

When you start coding, first of all, you should include libraries that you wish to use. The C++ language has many libraries and each of them has commands or functions for specific tasks. For example, the iostream library has standard input and output methods to display data and read from files and similar sources. Generally, for beginners, the iostream header is enough to enable you to create simple apps. We can include this library header as below,

Second, you should add a main procedure. This is the main part of the program – hence the name – and it is executed first. In the simplest sense, all other parts of your program are launched from the main section either directly or indirectly. Things get a little more complicated than that once you start to write more complex programs but for now you can think of the main section as the ‘main loop’ where things begin to happen in your program code.

After that you should write your lines of program code into this procedure, between the { and } brackets. You can print texts by using std::cout as below,

In C and C++, after every command you use you should put a semicolon “;”. In our example we print a text with std::cout method and then we wait to get a character input (key press) with system("pause"); method, then we exit and return 0; which means our main app has run successfully and exits.

If we sum up all, here is a “Hello World” C++ example below that can be run with C++ Builder.

In this example above we define main() function as an integer (int) function, that means we should return an integer value. Here, we print a text with printf() function and then we wait to get a character input (key press) with getchar(); function, sometimes this is necessary to see results when running it. Then we exit and return 0; which means our main app successfully ran and exited.

You can write these C++ code above into the Dev-C++ code editor or you can copy and paste it. If you are a beginner, we highly recommend you write code. This will help you to understand how C++ works and you can see your first mistakes when you are coding.

After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons. This will print out the “Hello LearnCPlusPlus”. C++ compilers support C language too, you can compile the C example below,

How to do calculations in a C++ console application?

Here is another C++ example that calculates the weight of a mass by using F =m.a formula (or W = m.g),

After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons. This will print the F Force value.
Normally, here you should use float for the m variable, we use int to teach how you can use int variable.

How to enhance our C++ console application?

We can improve our code as shown below.

After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons. Here is the output

How to get input in a C++ console application?

Now, let’s enter these all variables and our name as a string. This example is good to learn how you can use std::cin to get inputs.

After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons. Here is the output:

How to use loops in a C++ console application?

In engineering, if you want to calculate precisely you can use double instead of float variables. Let’s calculate all masses between 0 and 100 (including 0 and 100). Todo this, we will use for() loop, and we increase m with m+=1.0.

After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons. Here is the output,

You can find many other examples on LearnCPlusPlus.org.

For more information on this feature, see Extending sizeof Proposal document.

Five Simple C++ Console Examples for Beginners C++ Builder logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17C++20Learn C++NumericsSyntax

How To Compute The Greatest Common Divisor And Least Common Multiple in C++?

C++C++17Language FeatureLearn C++

How To Use Skia Shader SkSL Shading Language Code in C++ Builder?

Artificial Intelligence TechC++C++17C++20Learn C++

How To Create Simple Generative AI Code In C++

C++C++17Language FeatureLearn C++

How To Use The SVG Image Format With Skia In C++ Builder