#include<iostream>
#include <cmath>
usingnamespace std;
using std::cout;
using std::endl;
using std::cin;
int find_next_prime (int,int);
int find_prev_prime (int);
bool Is_prime(int);
int main() {
int input = 0, p1 = 0, p2 = 0;
int a = 0, k = 4, b = 2, count2 = 0, d=0;
cout << " Enter an even number:";
cin >> input;
// Keep asking for input that's >=4
while ((input <= k) || ((input % 2) != 0))
{
cout << " Enter an EVEN number please :";
cin >> input;
}
p1 = 2;
p2 = find_prev_prime(input);
while (p1 <= p2) {
// if two primes are less than our number, bump up smallest prime.
if (( p1 + p2 ) < input ) { p1 = find_next_prime (p1, input); }
//if two primes are greater than input, lower our highest prime.
elseif ((p1 + p2 ) > input ) { p2 = find_prev_prime (p2); }
///
///
///
else {
cout << "one pair is:" << p1 << " and " << p2 << endl;
p1 = find_next_prime(p1, input);
p2 = find_prev_prime(p2);
}
}
cout << "Done!" << endl;
// return EXIT_SUCCESS
return 0;
}
// find the next lowest prime after n.
int find_prev_prime(int n) {
n--;
}
//finds the next prime after n.
int find_next_prime(int n, int max) {
n++;
while (!Is_prime(n) && (n < max)) {
n++;
}
return n;
}
// Simply checks if the number is prime.
bool Is_prime (int n) {
for (int i = 2; i < n; i++ ) {
if ((n % i ) == 0 ) {
returnfalse;
}
}
returntrue;
}
When I compile the code and for example I enter 12, it doesn't return anything. whatever even number I enter it just doesn't show anything!!
To make it clear. I want to write a code that for example if I enter: 4 it gives me as answer: 2+2