Print the maximum of any two integer numbers the user enters. - C++ Statement

C++ examples for Statement:if

Description

Print the maximum of any two integer numbers the user enters.

Demo Code

#include <iostream>
using namespace std;
void findMax(int, int);  // function prototype
int main()//from  w ww.  j  a  v a 2s  . c  om
{
   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

Result


Related Tutorials