Console window isnt displaying anything!!!

closed account (LN7oGNh0)
OK, I am doing problem number 3 from ProjectEuler. (Just to let you know, this is an amazing site if you really want some hard problems to help better your C++ knowledge and mathematical knowledge.)I think Ive got something here... (Maybe I dont) but not a single error or warning comes up and when the console window opens.NOTHING IS THERE!!! PLEASE HELP ME FIX THIS!!! ALSO! DO NOT TELL ME THE ANSWER! THAT IS THE ABSOLUTE WORST THING YOU COULD DO!!! anyway... Ya, I need some help.

Heres the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include < iostream>

using namespace std;

//Foward declaration of function used to find the remainder
int findRemainder(int x, int y)
{
	return x % y;
}

int main()
{
	//all variables
	int num = 2;
	long long int primeFactor = 600851475143;
	int result = primeFactor % num;
	do
	{
		//Function that will find remainder
		int findRemainder(primeFactor % num);
		//If statements will make sure that only factor of primeFactor are displayed
		if (result = 0)
		{
			cout << num;
		}
		else
		{
			;
		}
			//For loop will test every number until it gets result = 0
			for(int num = 3; result = 0; num++)
			{
				int result = primeFactor % num;
				long long int primeFactor = 600851475143;
				int findRemainder(primeFactor % num);
				if (result = 0)
				{
					cout << num;
				}
				else
				{
					;
				}
			}
	}while(result = 0);
cin.get();
return 0 ;
}

Dont tell me the answer. >:-(
Thanks!

EDIT:
I know that the number called 'primeFactor isnt really a prime number... or a factor. I will fix that later.

EDIT: Sorry, forgot to say what the program is supposed to do. It is supposed to find a factor of 'primeFactor'. So i made the program go into a loop so that it keeps finding whether the remainder is 0 and when it is, the loop will be terminated.
Last edited on
Honestly, after 70 posts you should know by now how to put your code in code tags so that it looks neater and more readable...
closed account (LN7oGNh0)
Sorry, dont think ive seen a code tag. is it where the format buttons are?
closed account (LN7oGNh0)
Wow! that looks a lot better!
Alright, so now can anyone help me?
@Hazique35

Remember, a single =, is to assign an value to a variable, whereas a double ==, is to check validity of a value. Your program has many assigns, where they should be checking. Also, for(int num = 3; result = 0; num++), is not a correct for loop. Maybe you should use a do/while loop.
1
2
3
4
do
{
... Your program ...
} while(result!=0);

There are other problems. After creating an int, etc., you do not put the int word in front of the variable when assigning it another value later in the program.
1
2
int my_number = 10;
my_number = 24; // not int my_number = 24; 


Good luck..
closed account (LN7oGNh0)
OK, I will try that.
closed account (LN7oGNh0)
This is my new program, but it is still not displaying anything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include < iostream>

using namespace std;

//Foward declaration of function used to find the remainder
int findRemainder(int x, int y)
{
	return x % y;
}

int main()
{
	//all variables
	int num = 2;
	long long int primeFactor = 600851475143;
	int result = primeFactor % num;
	do
	{
		//Function that will find remainder
		++num;
		int findRemainder(primeFactor % num);
		if (int result = 0)
		{
			cout << num;
		}
		else
		{
			;
		}
	}while(result == 0);
cin.get();
return 0 ;
}


Is there anything else wrong? I took out the for loop and just kept the do-while one. I also made sure every int value had integer before it. (except if the type name was not allowed). Is it because my computer isnt able to handle a long long int?
Last edited on
@Hazique35
You're only going to be able to check one or two numbers, before the program ends. So, check with 100 nums instead. Even if you use 1000, it still only prints 3 numbers. But it's a start..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include < iostream>

using namespace std;

//Foward declaration of function used to find the remainder
int findRemainder(int x, int y)
{
	return x % y;
}

int main()
{
	//all variables
	int num = 1;
	long long int primeFactor = 600851475143;
	int result;
	do
	{
		//Function that will find remainder
		result = findRemainder(primeFactor, num);
		if (!result)
		{
			cout << num << endl;
		}
		num++; // Increase num after result check
	}while(num  < 100);
cout << "Program is done!!" << endl;
cin.get();
return 0 ;
}
closed account (LN7oGNh0)
Thanks!
closed account (LN7oGNh0)
What does the part with !result do?
@Hazique35

!result means 'not result' or 'if result == 0', or any negative number. Try removing the !, to leave just the result, and you'll show a lot more numbers .
closed account (LN7oGNh0)
I took off the '!' and no results came up.
@Hazique

Not sure why your version didn't show anything, but I'm running this and get numbers up to 99, then it prints "Program is done!!". I changed your large number to 65535. I get the same results, but not the conversion error of possible data loss converting from _int64 to int

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include < iostream>

using namespace std;

//Foward declaration of function used to find the remainder
int findRemainder(int x, int y)
{
	return x % y;
}

int main()
{
	//all variables
	int num = 1;
	int primeFactor = 65535; // lowered value here from original
	int result;
	do
	{
		//Function that will find remainder
		result = findRemainder(primeFactor, num);
		if (result) // Removed the ! here
		{
			cout << num << endl;
		}
		num++; // Increase num after result check
	}while(num  < 100);
cout << "Program is done!!" << endl;
cin.get();
return 0 ;
}
closed account (LN7oGNh0)
Ya. Thanks anyway. Pretty much almost finished solving the problem.
Topic archived. No new replies allowed.