positive remainders returning negative?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int Fib1 = 1;
int Fib2 = 2;
int Fib3 = 0;
int randomynumber;
int Loop;

while (Loop < 100) {
Fib3 = Fib2 + Fib1;
Fib1 = Fib2;
Fib2 = Fib3;
randomynumber = Fib2 % 17;
cout << randomynumber << " ";
if (Loop % 10 == 0) {
cout << "\n"
}
}

this returns negative numbers sometimes
what did i do wrong

side note this is not the complete program it is only the part with the problem because the complete code is sort of longish and very confusing
Last edited on
overflow
there is a limit on the numbers that an int may store http://www.cplusplus.com/reference/climits/

You may use modular arithmetic
(a+b) mod c = (a mod c + b mod c) mod c
Last edited on
thanks that worked perfectly
i didn't expect them to get so big so fast
Last edited on
Topic archived. No new replies allowed.