Cpp - Write program to define a function to add two integer together

Requirements

Write program to define a function to add two integer together

main() program should call an add() function to add two different sets of numbers together and display the results.

The add() function takes two integer parameters named x and y and adds them together in a return statement.

Demo

#include <iostream> 
 
int add(int x, int y) 
{ 
    std::cout << "Running calculator ...\n"; 
    return (x+y); 
} 
 
int main() /* ww  w.  j a v  a 2  s. com*/
{ 
    std::cout << "What is 8 + 5?\n"; 
    std::cout << "The sum is " << add(8, 5) << "\n\n"; 
    std::cout << "What is 7 + 3?\n"; 
    std::cout << "The sum is " << add(7, 3) << "\n"; 
    return 0; 
}

Result

Related Exercise