Addition of two numbers

Program Description

Take two numbers from the user (integer values) and display their sum

Program
/**************************************************************
*
* code.cheraus.com
*
* A simple program for addition of two numbers. Asks the user for two
* integers and outputs their sum. Does not deal with float values.
*
****************************************************************/

#include<iostream>
using namespace std;
int main()
{
 int num1=0;      //integer variable to hold first number
 int num2=0;     //integer variable to hold second number
 int num3=0;     //integer variable to hold the sum

 cout<<"Enter the first number: ";    //prompts the user for input 
 cin>>num1;                     //takes the input from keyboard

 cout<<"Enter the second number: ";   //prompts the user for second number
 cin>>num2;                     //takes the asecond input from the user

 num3=num1+num2;                       //perform addition and saves the result in num3

 cout<<"\nThe addition of the two numbers is "<<num3;  //prints the result

 return 0;                           // returns from the program indicating successful run

}

Output
Test Case 1:

Enter the first number:3
Enter the second number:2
The addition of the two numbers is 5

Test Case 2:

Enter the first number:-1
Enter the second number:2
The addition of the two numbers is 1

Comments
comments powered by Disqus