Salutations! I am having a lot of trouble trying to create a program that will test the validity of a user entered password. Below is the criteria of the test:
1. The password must be 6 digits long entered as a single integer (assume no leading zeros are entered – for example: 002345 is only 4 digits for our purposes).
2. All the digits in the number have to be unique.
3. The sum of the digits must be a prime number.
4. The largest digit (n) “choose” the left-most digit (k) must be even—for example: in 645923, the largest digit is 9 and the left-most is 6.

I am trying to use digit extraction and integer devision to accomplish this but I do not understand it yet (im a student).
I believe I could use something like digit = (num % 10) num = num/10 at least for the first digit? Also I can compute basic "n choose k" situations by hand but I could use some guidence for coding.
* I am using CodeBlocks with the GNU Compiler and iostream library *
Any advice is appreciated!!
-A

Recommended Answers

All 5 Replies

Each test you listed might be a function. Since it's a string, you'll have fun with string functions too. Show some code and tell why you think it failed.

One way is to create a function,that returns a boolean, for each validation step. If each step is true the password is valid. This way you can concecntrate on each step and get it right before moving on.

i thought of the boolean route but i dont know how to implement it. I cant even get the Part 1 to work

Post your Part 1 code subroutine. Tell what you think is the matter. Avoid "it doesn't work."

i thought of the boolean route but i dont know how to implement it. I cant even get the Part 1 to work

Think about what are the biggest and smallest numbers that have six digits, all valid pass codes must be between these two values, right :)

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.