0

This is my prompt. Write a program that asks the user how many twin primes the user wants to find, reads in that goal, and then successively examines the numbers starting at 2 to see if the number is a twin prime. The program stops when the specified number of twin primes has been found. It then prints out the twin primes found.

I've searched this forum and I found a lot of stuff on twin prime numbers up to 100, but I can't figure out how to make it defined by the user. It's been years since I've done C++ so I've forgotten a few things, but I 'borrowed' the loops from cgcgames, a user here.

Here's what I have:

```
#include <iostream>
#include <math.h>
using namespace std;
int main () {
int testnumber = 3; //declares the number that will be tested on. this is the first prime
int findingprime = testnumber - 1; // the number that is used to divide by testnumber to check if there is a remainder
int numberoftwins; // number of twin prime numbers
cout << "Twin Prime Numbers \n";
cout << "---------------------------------------------\n";
cout << "How many twin prime numbers would you like to find?" << endl;
cin >> numberoftwins;
int number=numberoftwins*2; // sets number to twin values(doubles)
while (testnumber < 100 how do I make this defined by the user?) { //loops while primes are under 100
if (testnumber%findingprime == 0) { // check for to see if there is no remainder and if there is its not a prime number and adds 2 the testnumber to start testing the next number
testnumber = testnumber + 2;
findingprime = testnumber - 1;
}
else { //else if there is a remainder it takes one of the finding prime variable and reruns the loop
findingprime = findingprime - 1;
}
while (findingprime == 1) { //if it goes through all the looping and finding prime is equal to 1 then that means testnumber is a prime
cout << testnumber << "\n"; //print the prime to the screen
testnumber = testnumber + 2;//moves onto next number
findingprime = testnumber - 1; // sets findingprime to one lest then testnumber
}
}
cout << "jhijhgijfhg" << endl; // this line has no purpose
cin.get(); // waits for user to press enter to stop the program.
```