#include <iostream>
#include <ctime>
int findSecondMax(int total, int rndmax) {
int max, before_max, n;
max = before_max = n = rand() % rndmax + 1;
std::cout << n << std::endl;
for (int i = 1; i < total; ++i) {
n = rand() % rndmax + 1;
std::cout << n << std::endl;
if (n > max) {
before_max = max;
max = n;
} else if (n > before_max) {
before_max = n;
}
}
return before_max;
}
int main() {
std::srand(static_cast<unsigned>(std::time(nullptr)));
int secondMax = findSecondMax(10, 100);
std::cout << "The second biggest number is: " << secondMax << std::endl;
}
/*
run:
88
58
46
11
79
55
56
92
18
56
The second biggest number is: 88
*/