Hello guys!

I have to make a program in c++ that displays on the screen all the friends numbers <= n . For example , if n is 11 then it should display the pairs :

(3,5);(5,7)

Friends numbers are those numbers whose difference is 2 and both numbers are prime. The difference between 5 and 7 is 2 and they are prime.The same is for 5 and 7,11 and 13 and so on.

Here is my piece of code and it doesn't work....

Code:

#include <iostream>
using namespace std;
int main(){
int n,d1,a,b,ok1,ok2,d2,i;
cin >> n;
for (a = 3;a < n;a++) {ok1 = 0;
for (d1 = 2;d1 <= a/2;d1++)
if (a % d1 == 0) ok1 = 1;}
if (ok1 == 0) {
for (a = 3;a < n;a++) b = a+2;
ok2 = 0;
for (d2 = 2;d2 <= b/2;d2++) {
if (b % d1 == 0) ok2 = 1;}
if (ok2 == 0) cout << "(" << a << "," << b << ")" << ";";
a++;
}
}
return 0;
}

Could someone help me out with the program ?

Thanks in advance !