Returning a Value from a Function
#include <iostream>
using namespace std;
int addNumbers(int, int);
int main ()
{
int firstNum, secondNum, sum = 0;
cout << "Enter first number: ";
cin >> firstNum;
cout << "Enter second number: ";
cin >> secondNum;
sum = addNumbers (firstNum, secondNum);
cout << firstNum << " + " << secondNum << " = " << sum;
return 0;
}
int addNumbers (int x, int y)
{
return x + y;
}
Related examples in the same category