C++ Function Definition Declare, call, and store a returned value
#include <iostream> using namespace std; int findMax(int, int); // function prototype int main()// www . j a v a2s . 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 }