Overload the min() function.
#include <iostream>
#include <cctype>
using namespace std;
char min(char a, char b);
int min(int a, int b);
double min(double a, double b);
int main()
{
cout << "Min is: " << min('x', 'a') << endl;
cout << "Min is: " << min(10, 20) << endl;
cout << "Min is: " << min(0.2234, 99.2) << endl;
return 0;
}
// min() for chars
char min(char a, char b)
{
return tolower(a)<tolower(b) ? a : b;
}
// min() for ints
int min(int a, int b)
{
return a<b ? a : b;
}
// min() for doubles
double min(double a, double b)
{
return a<b ? a : b;
}
Related examples in the same category