C++ examples for Function:Function Return
Declare, call, and store a returned value from a function
#include <iostream> using namespace std; int findMax(int, int); // function prototype int main()//from w w w .j a v a 2 s . com { int firstnum, secnum, max; cout << "\nEnter a number: "; cin >> firstnum; cout << "Great! Please enter a second number: "; cin >> secnum; max = findMax(firstnum, secnum); // function is called here cout << "\nThe maximum of the two numbers is " << max << endl; return 0; } int findMax(int x, int y) { // start of function body int maxnum; // variable declaration if (x >= y) // find the maximum number maxnum = x; else maxnum = y; return maxnum; // return statement }