This is a program to learn how to calculate the sum of two numbers in c++. First, you write a basic structure of the c++ program in your editor.
After following the previous step you can write the below code in your editor. You should create Two integer variables in void main function in the c++ program. Then use an arithmetic operator for addition. After you must create one more variable in the c++ program to store the value of the addition.
Also Read This :- hello world program in c++
You should give value to a variable, otherwise, the compiler will give a zero or garbage value to a variable.
Example of sum of two numbers in C++
#include <iostream> using namespace std; int main() { int first_number, second_number, sum; cout << "Enter two integers: " << endl; cin >> first_number >> second_number; // sum of two numbers in stored in variable sumOfTwoNumbers sum = first_number + second_number; // prints sum cout << first_number << " + " << second_number << " = " << sum; return 0; }
output
Enter two integers: 4 6 4 + 6 = 10
After writing a successful program and closing the program with return (0). After You should compile your program for checking any errors and run it.
If your program will run successfully and returns the sum of two variables, you should learn the next step in c++.