Finding the sum of the numbers between two integers can be done as follows: int i = x + 1; // we start counting 1 higher then x // or make this i = x if you want to include x int sum = 0; while (i < y) { // repeat while we haven't reached y // or make this i<=y if you want to include y sum = sum + i; i++; } voila. or shorter: int sum = 0; for (int i=x+1;i