Member Avatar for _Michael_

Hello, I am making a console application for a window home computer. The application will search for factors of a number that the user enters. Everything works fine up to about [10^10 = 10000000000]. I am unsure if C++ has a maxium number allowence. If this is the case can you please tell me. Otherwise here is the code I made:

#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;
int main(){
	bool Running = true;
	cout << "*****************" << endl;
	cout << "* FACTOR FINDER *" << endl;
	cout << "*****************" << endl;
	cout << "MADE BY MICHAEL HARRISON" << endl;
	cout << "\n";
	cout << "AFTER ENTERING A NUMBER PRESS THE RETURN KEY TO FIND ITS FACTORS" << endl;
	long double Check_Number = 0;
	long double The_Number = 0;
	cin >> The_Number;
	long double sqrt_The_Number = int(sqrt(The_Number))+1;
	long int i = 2;
	long int Total_Factors = 0;
	cout.setf(ios::fixed); 
	cout.precision(0);
	while (i < sqrt_The_Number){
		Check_Number = The_Number/i;
		if (Check_Number == int (Check_Number)){	
			cout << Check_Number << " * " << i << endl;
			++Total_Factors;
		}
		++i;
	}
	if (Total_Factors == 0){
		cout << "THIS NUMBER IS PRIME";
	}else{
		if (sqrt(The_Number) == int(sqrt(The_Number))){
			cout << "TOTAL NUMBER OF FACTORS: " << Total_Factors * 2 - 1;
		}else{
			cout << "TOTAL NUMBER OF FACTORS: " << Total_Factors * 2;
		}
	}
	cout << "\n" << "\n";
	return 0;
	cin.get();
}

It doesn't matter if this isn't thew most efficient way, I just want it to work. I would be very greatful if someone could answer this post. Thanks.

limits.h contains the maximum and minimum values for integers.

Member Avatar for _Michael_

So how do I use this limits.h?

just like you would use any other header file: #includle <limits.h>

Member Avatar for _Michael_

Thanks

Member Avatar for _Michael_

I tried it, but what does it do?
There wasn't any change in the outcome of my application?

If you look inside limits.h you will see the maximum values allowed -- and the name of the variable representing the number

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.