I'm trying to write a program in C++ that will prime factor numbers that have 12 digits. Here's my code:
#include <iostream>
using namespace std;
int main()
{
long double userInput;
long double divisor = 2;
long double dividend;
cout << "Enter number: ";
cin >> userInput;
dividend = userInput;
do
{
while (static_cast<int>(dividend) % static_cast<int>(divisor) == 0)
{
cout << divisor << endl;
dividend = dividend / divisor;
}
divisor++;
} while (dividend > 1);
return 0;
}
This (seems to, at least) works fine for smaller numbers, but it breaks down when I use really high numbers. Why is this? Do I need to use a larger integer type? Or is it something wrong with the code itself?