### Prime number between two intervals

I am trying to get prime numbers between two intervals. I have a function is_Prime to check if a number is prime or not and returns true or false. I have another function countPrimes to find prime numbers between two intervals using the is_Prime function.

When I input 12 20. The output I get is all the numbers between 12 and 20 instead of the prime numbers only.

 ``12345678910111213141516171819202122232425262728293031`` ``````#include using namespace std; int n, i; bool is_Prime(int n){ if (n < 2){ return false; } for (int i = 2; i < (n / 2 + 1); i++){ if (n % i == 0){ return false; } } return true; } int count_Primes(int x, int y){ while(bool is_Prime = 1) is_Prime++; } int main(){ int i; int x; cin >> x; int y; cin >> y; for(int i = x+1; i < y; ++i){ cout << i << endl; } return 0; }``````
Last edited on
`while(bool is_Prime = 1)`What do you expect from this loop ?
Also you count_Primes doesn't return a value.
Maybe have a look in your textbook about functions and return values.

It would be much easier to use a for loop from x to y and call your is_Prime for each value. If it is a prime increment a counter. At the end of the function return the counter.
the first thing i do is avoid naming two variables in the same way, no matter whether one is local or not..then state two variables (in your code those are int n, i) and make them as start and end point of iteration and just crate a formula to figure out a prime number and have it return something..at least that's how i do algo jobs from https://www.upwork.com/ https://www.writemyessayfast.org
good luck