I'm writing a function that checks the Collatz conjecture. While doing this I also check if the number gets/is bigger than INT_MAX. But when i give a number bigger than INT_MAX as input, it just makes it INT_MAX. Because of this I can't check it. Is there a way around it?
the function:
#include <iostream>
#include <climits>
using namespace std;
bool limit = false;
int collatzCheck(int num) {
limit = (num > INT_MAX || num <= 0);
cout << "start: " << num << endl;
int i = 0;
while(num != 1 && !limit) {
cout << ".." << endl;
if(num%2 == 0) {
num /= 2;
} else {
limit = (num > (INT_MAX-1)/3);
if(!limit) num = num*3+1;
}
cout << num << endl;
i++;
}
return i;
}
int main() {
cout << "INT_MAX: " << INT_MAX << endl;
int num;
cout << "num: ..";
cin >> num;
cout << "Iteraties: " << collatzCheck(num);
if(limit) cout << ", INT_MAX is wel bereikt.." << endl;
else cout << ", INT_MAX is niet bereikt!" << endl;
return 0;
}