.exe does not work!! Where is the error?

Hi there,

I am trying to write a program which checks if every even number in an interval (a,b) can be portrayed as the sum of two prime numbers.
In the end the even number with the fewest representations as sum of prime numbers should be in the output.

There are no errors shown, but the execution file will only work until you type in the numbers a and b for the interval.

I think i did a mistake by using vector there. Can anybody help?

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
87
88
 #include <iostream>
#include <vector>

 using namespace std;
 
 
bool is_prime(int n)  //function that proves if a number is prime
{
    
    if (n < 2) {
        return false;
    }

    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
           return false;
        }
    }
    return true;
}


void print_vector(int min, int min_count, std:: vector<int>& min_comb){				

cout << "the even number with the fewest representations is:" <<min<< "\n"
			<<"The representations are: "<< endl;
			for (int i=0; i<min_count; ++i){
		cout << " "<<min_comb[i]<<"+"<<min-min_comb[i]<<"\n";
		}
}



 int main ( )
  {
    int a, b;   			//interval 
    int k,j, p;				//variables 
	
	int min;				//number of minimal representat.
	int min_count=b;			//
	int count; 				//Number of represent. in total

	vector<int> comb(b/4);		

//this vector with size b/4 saves one primesummand of each representation

	vector<int> min_comb(b/4);	

//this vector saves the primesummands of the number with the fewest representations 	
		
	
    cout << " 1. Type in start number : "; 
	cin >> a;
	cout << " Type in end number : "; 
	cin >> b;

      for (int i=a; i <=b; i=i+1){  			
        
     count=0;  \\number of represntations
      
        if (i %2==0) {  	//only consider even numbers
	
       for (k=2; k<= i/2; ++k){		

           if ( is_prime(k)){  				
            if ( is_prime(i-k) ){
            	comb[count]=k;				
            	count ++;					
			}
}		
		 }		 
    } 	
    	if (count < min_count){
    		min = i;					
    		min_count = count; 			
    		
    		for (count-=1; count >= 0; --count){
    			min_comb[count] = comb[count];	
				}
			
	}
    		
}

		print_vector(min, min_count, min_comb);		
		

}
You need to wait to use b until after you have given it a value.
Thank you!!

Does that mean that I should define the vectors after I get a value for b?
It really worked, thats amazing!!

now it shows me which prime number has the fewest representations.
But the representations themselves arent shown.
What can I do to fix the problem?
Topic archived. No new replies allowed.