Hello,
I am looking to make a program that will generate prime numbers. The program has to start at a specific number, ex: 3698741 and then end at another specific number, ex: 9874123. The numbers may never have duplicate digits, ex: 9874122. There will be a set of rules as to what numbers can follow others, ex: 6 & 9 can follow 3 but not 2 or 1.

Now, I will not even call myself new to C++ because that would be an understatement. However, if I can get any tips on how to code these specific functions that would be great. If someone wants to code the whole thing that would even be better. But, realistically, any help would be appreciated.

In the end the program should output all of the generated numbers into a list.

Thank you,
Paul

Hello,
I am looking to make a program that will generate prime numbers. The program has to start at a specific number, ex: 3698741 and then end at another specific number, ex: 9874123. The numbers may never have duplicate digits, ex: 9874122. There will be a set of rules as to what numbers can follow others, ex: 6 & 9 can follow 3 but not 2 or 1.

Now, I will not even call myself new to C++ because that would be an understatement. However, if I can get any tips on how to code these specific functions that would be great. If someone wants to code the whole thing that would even be better. But, realistically, any help would be appreciated.

In the end the program should output all of the generated numbers into a list.

Thank you,
Paul

No one is going to code the whole thing for you. It's against the forum rules. There are a variety of ways to do it and the overall task can be split into smaller tasks. First you need your algorithm/method. Depending on how efficient you want to be, you can create a "smart" algorithm that will be more complicated, but faster, or a "dumb", brute force one that is uncomplicated, easier to code, but slow. As you are new to C++, my advice is to make life easier and do the "dumb/brute force", easier to code way.

If you decide to go the "dumb" route, you can have a function that checks whether a number is prime:

bool isPrime (int number); // returns true if number is prime, false otherwise

I'd get that one working first, then worry about your other stipulations. Write a nice little program that calls isPrime and passes it a number like 5 and displays whether 5 is prime or not. When that's working, add more.

That is helpful. No, I didn't really expect anyone to code the whole thing. The other thing that I need help on is how to stipulate the sequence of numbers that can be produced, ex: 6 can follow 3 but not 2 or 1. The other things is a rule that wont allow duplicate digits in a number.
thanks.

That is helpful. No, I didn't really expect anyone to code the whole thing. The other thing that I need help on is how to stipulate the sequence of numbers that can be produced, ex: 6 can follow 3 but not 2 or 1. The other things is a rule that wont allow duplicate digits in a number.
thanks.

More than one way to do both of these. One way involves isolating each digit of a number, then doing something with that array of numbers. Have you used arrays yet? Here's an example of how to isolate the digits. See post 11 of this thread.

http://www.daniweb.com/forums/thread199344.html

Another way is to turn the number into a string and search the string for a certain combination (i.e. "26" or "16").

Check out www.cplusplus.com. The cstdlib, string, and cstring libraries could be useful here. In particular, check out these functions:

c_str
atoi (may have portability problems. Can't remember.)
itoa (may have portability problems. Can't remember.)
The "find" function from the string library.

These all have helpful string manipuation and int to string and vice versa capabilities. I don't have time to link them right now, but check out the site. There are other useful functions in those libraries too.

atoi() is portable itoa() is not

commented: Yes. +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.