Assuming you have an unknown set of data, you can always place it in an array / vector / list and run...
int res = *max_element( intList.begin(), intList.end() ); //where intList is the list
Which is as commented by @Yuushi : but expended on, since it can get quirky
#include <algorithm> #include <iostream> #include <list> #include <stdlib.h> #include <algorithm> // std::max using namespace std; int main() { list<int> intList; int a, b; int maxItems = rand() % 40 + 10; //10 to 50 items cout << "=== Testing a maximum of " << maxItems << " values ===\n"; cout << "generating random value set: {"; for( a = 0; a < maxItems; ++a ) { b = rand() % 100; cout << b << ", "; intList.push_back(b); } cout << "}\n"; //Note max element inputs iterators, and outputs the max value iterator! //-> which is the pointer to the actual value (hence * to get value) a = *max_element( intList.begin(), intList.end() ); cout << "max value generated = " << a << "\n"; return 0; }
Which can give a sample result as below
=== Testing a maximum of 33 values === generating random value set: {86, 77, 15, 93, 35, 86, 92, 49, 21, 62, 27, 90, 59, 63, 26, 40, 26, 72, 36, 11, 68, 67, 29, 82, 30, 62, 23, 67, 35, 29, 2, 22, 58, } max value generated = 93
for( x : list ) val <= highest(x);? But this is a better question for StackOverflow not CodeReview. \$\endgroup\$val = max(A, max(B, C))? \$\endgroup\$