Addition Program In C++: Analogy-Based Examples

Let us start our programming journey with a simple addition program for beginners. This article will take you through the declaration to get the output of an additional program in C++.
authorImageVarun Saharawat30 Oct, 2025
Addition Program In C++: Analogy-Based Examples

Additional program in C++: With programming, we can learn to solve various real-life problems easily. As a beginner, adding two numbers is the best starter. Let us learn to write additional programs using C++ language. The Additional program evaluates the sum of two or more numbers. We will also understand the concept based on analogy-based examples.

In this blog, you will learn the best way to add two variables using a C++ program code. Learning C++ language is very easy. Check the implementation below.

Algorithm for Addition Programming in C++ 

Let us check the algorithm for calculating the addition in C++
  • Step 1: Start
  • Step 2: Declare three different variables containing two variables and a variable for storing the sum after addition.
  • Step 3: Read the number from the user using the prompt.
  • Step 4: Similarly read the other input from the user.
  • Step 5: Now find the sum using the addition operator easily and store it in the sum variable.
  • Step 6: After calculating the sum, display using ‘printf’ function in CPP.

Addition Program using C++

Check the table below to find the addition of two numbers using a C++ program.
Addition Program in C++
#include <stdio.h> int main() {     // Declare variables     int n1, n2, sum;     // Prompt the user to enter two integers     printf("Enter two integers: ");     // Read two integers from the user     scanf("%d %d", &n1, &n2);     // Calculate the sum of the two numbers     sum = n1 + n2;     // Print the result     printf("%d + %d = %d\n", n1, n2, sum);     return 0; }
  • Let us declare three variables, n1, n2, and sum to store two numbers and ‘sum’ to store the result of addition.
  • Now, let us prompt our users to provide the numbers to add.
  • Scan the input code and store the addition in sum.
  • At last, we print the result using built-in function ‘printf’.

Also Check: What is DevOps? Simple Explanation

Analogy Based Addition Program in C++

Problem Statement: Juice mixer Counter

Description: Let us take a real-world example of an additional program in C++. Suppose you are a juice maker and you are making lemon juice for your customers. 

You need to have two containers, one containing lemon extracted juice and other containing water. You need to add the two containers together to make the mixture. Suppose the two containers hold two variables. Now we need to add these two variables in a separate container and mix them together.  

Objective

The objective of the program is to add the two items to make a lemon juice mixture.
  • Store the two variables in separate containers.
  • Now add the two container items to calculate the total amount of mixture
  • Now, display the total amount of mixture in the new container.
Addition Program in C++
#include <iostream> using namespace std; int main() { double com1, com2, mix; count<< “Enter the quantity of component 1(ml): “; cin >> com1; cout<<” Enter the quantity of component 2 (ml): “ cin>>com2; mix = com1 + com2; cout<<” The mixture after addition forms: “ <<mix<<” ml<<endl; return 0; 

Output

Enter the quantity of component 1 (ml):  Enter the quantity of component 2 (ml): 10  The mixture after addition forms 15 ml 

Learn C++ with PW Skills

Join our DSA With C++ Course to learn more real-world problems to shape your programming skills and find various opportunities as a software developer, programmer, etc. The course consists of recorded lectures from top experts guiding you through complete C++ beginner to advanced level.  Also, get 100% placement assistance and a course completion industry-recognized certificate after completing the course. Hurry and grab exciting offers for this course only at @pwskills.com

Addition Program using C++ FAQs

How do you do addition in C++?

For addition using C++ programming language you can use simple addition arithmetic operator (+). First declare a variable that holds the two values and then declare a variable to store the sum of two variables.

How do you make a sum in C++?

Algorithm to add two numbers in C++ Start Declare three variables n1, n2, and sum. Now, prompt our users to provide the numbers to add. Scan the input code and store the addition in sum. At last, we print the result using built-in function ‘printf’.

Is there a sum function in CPP?

You can use the accumulate() function which is included in <numeric header file. This function takes three parameters to calculate the sum.

What is the sum() function?

The sum() function is used to add values.