Code is not working

closed account (LN7oGNh0)
This code is supposed to find the remainder of a very large number, then show the number that was divided by the very large number. (only if the remainder is equal to 0)

Here is 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
#include < iostream>

using namespace std;

//Foward Decalration of function that will find the remainder of two values
long long int findRemainder(long long int x, long long int y)
{
	return x % y;
}

int main()
{
	long long int longNumber = 600851475143;
	long long int y;
	int result = findRemainder(longNumber, y);
	
	for(y = 2; result != 0; y++); 
	{
		findRemainder(longNumber, y);
	}

	cout << y;

cin.get();	
return 0;
}


I suspect that it might have to do with the integer 'y'. (I think I initialized it to 2, then initialized it again to 2 in the for loop. Warnings come up, but they go away as soon as the console window opens. Can anyone fix this?

Thanks!


EDIT: I just noticed that 'int result' is not a long long integer, so I have changed that.
Last edited on
My opinions:

Line 15: y is used without initiation. That statement is redundant actually.

Line 19: inside the loop, result is not updated. It should be result=...

Reading the whole program, it is like you want to find the first number completely dividing longNumber.
Variable y was not initialized. So this code has no any sense

1
2
	long long int y; // What is the value of y???
	int result = findRemainder(longNumber, y);


Also it is no clear what this statement does

for(y = 2; result != 0; y++);

Take into account the semicolon after the statement.

Last edited on
closed account (LN7oGNh0)
Ya, I addressed, the variable y not being initialized in the EDIT.

@chucthanh: Yes. Thats what i want.
Fixing line 19 as I said and line 17 as vlad said should work for you, I guess.
Topic archived. No new replies allowed.