Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

C++ How To Add Two Numbers

Add Two Numbers

Learn how to add two numbers in C++:


int x = 5;
int y = 6;
int sum = x + y;
cout << sum;
Try it Yourself »

Add Two Numbers with User Input

In this example, the user must input two numbers. Then we print the sum by calculating (adding) the two numbers:


int x, y;
int sum;
cout << "Type a number: ";
cin >> x;
cout << "Type another number: ";
cin >> y;
sum = x + y;
cout << "Sum is: " << sum;
Run example »