C++ Function Definition Print the maximum of any two integer numbers the user enters

Description

C++ Function Definition Print the maximum of any two integer numbers the user enters

#include <iostream>
using namespace std;
void findMax(int, int);  // function prototype
int main()/*w w  w  .j a  v  a2 s. com*/
{
   int firstnum, secnum;
   cout << "\nEnter a number: ";
   cin  >> firstnum;
   cout << "Great! Please enter a second number: ";
   cin  >> secnum;
   findMax(firstnum, secnum);  // function is called here
   return 0;
}
// Following is the findMax() function
void 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;
   cout << "\nThe maximum of the two numbers is "
   << maxnum << endl;
   return;
}  // end of function body and end of function



PreviousNext

Related