I Need HELP!!!

I'm working on a Goldbach’s conjecture code, which is that the sum of any number larger than 2 can be expressed by adding two prime numbers.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  
#include<iostream>
#include <cmath>

using namespace 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.
        else if ((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 ) {
            return false;
            
        }
    }
   
    return true;
}






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

8 = 3+5

and like that.


annnnnd... Thank you.
You should try stepping through the program that will make most problems obvious.

1
2
3
4
5
// find the next lowest prime after n.

int find_prev_prime(int n) {
    n--;
}

This function needs to return a value
Also to mention that is not how you find the next lowest prime :P

It should be

1
2
3
4
while( !Is_prime( n ) )
--n;

return n;
Topic archived. No new replies allowed.