Doing Project Euler problem 3.
Don't know why code not working.

#include<iostream>
using namespace std;


//largest prime factor 317584931803.

bool Primechecker(int);


int main()
{
	int greatestprime=1;
	int limit = 317584931803;
	int runningcount=1;
	
	while(runningcount<limit/2)
	{
		if (Primechecker(runningcount)==true && limit%runningcount == 0)
			{
			greatestprime = runningcount;
			}
		runningcount++;
	}
	

	cout << greatestprime;
	cin.get();
	return 0;
}

bool Primechecker(int num)
{
	for (int i=1; i< num/2; i++)
	{
		if (num % i == 0 && i != 1)
			return false;
	}
	return true;
}

Your limit is an int, which is too small to hold the number you have put in it. (Your compiler should have complained about this.) Try using a long long or somesuch.

Start runningcount at 2, not one.

Your primeChecker() function is fine, but it will be slow.

Hope this helps.

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.