This is a simple & easy C++ program to add two number entered by the user while executing this program. I assume you have basic knowledge of C++. In the below program, there are three variable x, y, and sum. x and y hold the value of entered by the user and then add the both number using add operator (+) and store into sum variable.
Finally, print the sum to see the program output. The output will be the addition of x and y:
sum = x + y
using namespace std;
int x, y, sum;
cout << "Enter two integers for addition: ";
cin >> x >> y;
// sum of two numbers in stored in variable sumOfTwoNumbers
sum = x + y;
// Prints sum
cout << x << " + " << y << " = " << sum;
Enter two integers for addition: 5
5 + 10 = 15
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.