Summation of two integers in C plus plus

In this c++ program we will receive two integers input and sum them up accordingly. We will create two variables that will receive the user input through the cin object (which will then extract user input and assigns it to the variable), then the program will print the outcome on eclipse’s console through the cout object. As previous article has mentioned before all the c++ program in this tutorial will be created through eclipse oxygen.

#include <iostream>
using namespace std;

int main() {

	int numberOne;
	int numberTwo;
	cout << "Enter First Number" << endl; // get the first number input
	cin >> numberOne;
	cout << "Enter Second Number" << endl; // get the second number input
	cin >> numberTwo;
	cout << "The sum of two numbers is " << numberOne + numberTwo << endl;
	return 0;

The outcome of the program is as follow:

Enter First Number
Enter Second Number
The sum of two numbers is 9

The above program will only receive integer input, if you enter a character input then it will not work as expected.

Leave a Reply

Be the First to Comment!

Notify of