I need to make a flowchart, mainly using do/while loops, that asks for two numbers A and B and displays every pair of twin primes between them. A must be smaller than B. For example, if A = 1 and B = 5, the result should be 3 and 5 because both numbers are prime and their difference is 2. I understand that I need to validate A and B first, but I am unsure how to test whether numbers are prime and how to find the twin-prime pairs.
2 Answers
A straightforward flowchart would first ask for A and B and repeat the input if A is greater than or equal to B. Set the current value to A, then repeat while current is less than or equal to B - 2. For each current value, test current and current + 2 for primality. If both tests succeed, print them as a twin-prime pair; then increase current by 1 and continue. You can skip even candidates except for 2, but checking every value is simpler for a first version.
Break the task into two smaller problems. First, create a prime-checking step: for a candidate number n, test whether any integer from 2 through n - 1 divides it evenly. If one does, n is not prime; if none do, it is prime. Then loop through the values from A to B - 2. For each value x, check whether both x and x + 2 are prime. If they are, output the pair. A do/while loop can be used for the divisor test and another can move through the range.
The important part is to finish and verify the prime-checking logic before adding the twin-prime condition. Once that works, the pair check is simply prime(x) AND prime(x + 2).

Be clear about the endpoints in your flowchart. Testing up to B - 2 ensures that the second number in a pair does not go beyond B.