Addition program that displays the sum of two integers. - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Addition program that displays the sum of two integers.

Demo Code

#include <iostream>

int main() {//  w ww  .ja  va 2 s  . com

   int number1{0}; // initialized to 0
   int number2{0}; // initialized to 0
   int sum{0};     // sum of number1 and number2 (initialized to 0)

   std::cout << "Enter first integer: "; // prompt user for data
   std::cin >> number1; // read first integer from user into number1

   std::cout << "Enter second integer: "; // prompt user for data
   std::cin >> number2; // read second integer from user into number2

   sum = number1 + number2; // add the numbers; store result in sum

   std::cout << "Sum is " << sum << std::endl; // display sum; end line
   return 0;
}

Result


Related Tutorials