Write Your First Simple C++ Program
The program receives integer values, sums, and displays the result

This program prompts the user to enter two values, computes and displays the sum of both numbers.
To write this simple c++ program you first need:
Variable
A variable is a container that holds a value in memory. eg. a, num, stu .etc
Declare a variable: helps c++ know the variable you are declaring.
What you need to declare the variable:
- Data type
- User (prompt to enter a value)
A data type defines what type of data a variable holds. eg. int, char, float .etc
User prompt: cout<<“Enter first number”<
Adding two numbers — C++ code
//CODE WITH COMMENTS
int a,b,c; //declares variable as an integer
cout<<"Enter first number"<<endl; //prompts user for first input
cin>>a; //input first value
cout<<"Enter second number"<<endl; //prompts user for second input
cin>>b; //input second value
c=a+b; //stores sum in c
cout<<"The sum of the numbers are \n"<<c<<endl; //displays final result
//CODE WITHOUT COMMENTS #1
int a,b,c;
cout<<"Enter first number"<<endl;
cin>>a;
cout<<"Enter second number"<<endl;
cin>>b;
c=a+b;
cout<<"The sum of the numbers are \n"<<c<<endl;//CODE WITHOUT COMMENTS #2
#include <iostream>
using namespace std;
int main() {
int a,b,c;
cout<<"Enter first number"<<endl;
cin>>a;
cout<<"Enter second number"<<endl;
cin>>b;
c=a+b;
cout<<"The sum of the numbers are \n"<<c<<endl;
return 0;
}Above is the result of the code in the online compiler JDoodle
An explanation of the code:
int is the data type integer that declares the variables a, b, and c as the storage location for integer values, cout<<“Enter first number”<<endl; prompts the user to enter the first number, cin>>a; accepts input from the user, cout<<“Enter second number”<<endl; and cin >>b; works the same as the previous, c = a + b; stores the sum of a and b, and cout<<“The sum of the numbers are \n”<c<<endl; displays the sum of the numbers.
Terminologies:
cout<< as output
cin>> as input
; as terminator
endl as inserts new line and flushes the stream
\n as break or inserts a new line
How the program works:
The program receives input data from the user as numbers, finds the sum, and displays the result.
