Question #58192

Write a c++ program that asks the user to enter a first number and then a second number and then displays the bigger number with a statement, then calculates the maximum inside a function which must be called theMax and must not have any inside console input or output.

Expert's answer

#include <iostream>

using namespace std;

int theMax(const int first, const int second) {
return first > second ? first : second;
}

int main() {
int a, b;
cout << "Enter first number: ";
cin >> a;
cout << "Enter second number: ";
cin >> b;
int max = theMax(a, b);
cout << "Max(" << a << ", " << b << ") = " << max << endl;
system("pause");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS