C++ Example Program: Area of a Circle
Browse articles:
Auto Beauty Business Culture Dieting DIY Events Fashion Finance Food Freelancing Gardening Health Hobbies Home Internet Jobs Law Local Media Men's Health Mobile Nutrition Parenting Pets Pregnancy Products Psychology Real Estate Relationships Science Seniors Sports Technology Travel Wellness Women's Health
Browse companies:
Automotive Crafts, Hobbies & Gifts Department Stores Electronics & Wearables Fashion Food & Drink Health & Beauty Home & Garden Online Services & Software Sports & Outdoors Subscription Boxes Toys, Kids & Baby Travel & Events

C++ Example Program: Area of a Circle

Writing a program to calculate the area of a circle in C++ is actually not too difficult. While there are different ways, it just goes to show that with computer programming, there is more than one way to write the same exact program. This example program is designed to make learning the language a lot easier.


Continuing in the series of doing calculations, this one involves the area of a circle.  The purpose of this is to demonstrate and show how to use different Math formulas in a program for calculation purposes only.  Difficulty level for this process would be that it is on the easy side.


#1: Knowing Mathematics is going to be necessary.

#2: Understanding the structure of a C++ program is a must.

#3: Having an understanding of different data types is going to be really helpful.


#1: The formula for area of a circle is A = PI * R^2.

#2: It is recommended to go with double as the answer format since PI is generally 3.14 in terms of an approximate value.

#3: This can be written in multiple ways.  Do it in the way that makes you feel the most comfortable.

#4: Warnings when compiling code do not automatically mean that there is an error.

Writing the program

#1: Open up the program of your choice.  At the minimum, it should be Visual C++ but if you have Visual Studio open it.

#2: Go to Visual C++ if using Visual Studio when going under new project.  Give it a name and use the template Win32 Console Application.  Have it set as an empty project.

#3: Once that has been completed, create a source file by using right click and have it as the extension .cpp.  Give the file a name and begin coding.

#4: Write the code out completely from beginning.  The screen shots below will demonstrate different ways of writing the same exact program.

Figure 1 is without a function.

Figure 2 is with functions but not returning a value.

#5: Double check and make sure that there are no possible errors.  Try to make sure the syntax is correct from beginning to end.  Without doing so, it will lead to frustration.

#6: Build the program.  It is necessary and will check if there are errors or not.  If there are errors, go to the next step.  Otherwise, simply skip it.

#7: If there are errors, go over the program and check every part.  Maybe it could be spelling or anything of that caliber.  Correct the errors involved and then go back and repeat the process.

#8: Simply execute the program and it should run without too much trouble.


That concludes finding the area of a circle.  Difficulty level is not too hard and it would be just on the easy side.  There will be more difficult programs to write.

Additional resources:

Need an answer?
Get insightful answers from community-recommended
in Computer Programming & Languages on Knoji.
Would you recommend this author as an expert in Computer Programming & Languages?
You have 0 recommendations remaining to grant today.
Comments (0)