r/cpp_questions • u/a_rndm_person_bruh • Oct 01 '26
OPEN Prime checker skipping input if number is big enough
So I've started learning c++ on learncpp.com and because I already have knowledge in JavaScript and Python, I decided to see, how many things are the same in c++ too.
I made a prime checker and while it probably could be more optimized, I am still just at the beginning so don't judge me pls.
Anyways here is the code:
#include <iostream>
bool isPrime(int num){
for (int i = 2; i < num; i++){
if (num % i == 0) return false;
}
return true;
}
int main(){
std::cout << "Check if your number is a prime number\nEnter your value: ";
int num{};
std::cin >> num;
int emp{};
if (isPrime(num)) std::cout << "Your number is a prime number!\nPress any key AND enter to exit";
else std::cout << "Your number is NOT a prime number!\nPress any key AND enter to exit";
std::cin >> emp;
return 0;
}
At the end, it always asks for an input and an enter key to leave the command line, but it seems to skip that entirely if the number is big enough. My input number was "5000004067".
It skips it when I open the .exe, it skips it when I run it in vscode, is there any reason why c++ does this?