I have to write a program that prompts the user to select (but not disclose) a number between 0 and 31 and then asks exactly five questions to determine the number the user has selected. Each of the five questions is posed by presenting a group of sixteen numbers, asking if the user's selected number is in that group. The program then determines and announces the user's number. Lastly, the program asks the user if he or she wants to do the activity again. If so, the process is repeated. If not, the program terminates.

This is the information I got, and I'm totally lost. I have to use loops like (for, or while). If you can help me I will appreciate it eternally :P

Requirement Notes

General

Each user answer is either "yes" or "no" (indicating whether or not the secret number is in the set currently displayed). Think how this might relate to the binary number sets.
Number Sets

It is required that you display the correct five sets (and their complements) of sixteen numbers. These sets are described below. While number elimination algorithms can yield the same results, they are much more easily noticed by users and thus appear less "magic".

The key to this assignment is understanding binary. The sets of numbers are generated by fixing the appropriate binary digit at 1.

The 2^4 set is the following:

16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31

The 2^0 set can be generated by starting with 1, then adding 2 repeatedly up to 31
The other sets of numbers can each be generated using a fixed pattern for each set; using these patterns will simplify your loops used to generate your sets of numbers
Complements

The complements can be thought of it two equivalent ways:
The sets are generated by fixing a binary digit at 1, while the complements are generated by fixing the same binary digit at 0

The complement of a set of numbers is the complete set of numbers (0 to 31) less the set itself; the complement of the 2^4 set is the set of numbers from 0 to 15
Once Part 3 is implemented, the user will likely see different sets upon each play through the game. The following are examples of what number sets the user may see from different plays of the game:

[set1, set2, set3, complement4, set5]
[complement1, complement2, set3, complement4, set5]
[complement1, set2, set3, set4, complement5]

Thank You a lot !! Hope you can help a newbie in this world of programming.

zios007
Deleted Member

Nice one, that :)
Your number is 5-digit in binary. Based on that, in each guess, you set one digit of the number to 1, and then output all the possibilities for the other four digits (which are exactly sixteen), if the user answers 'yes' - you leave that digit as 1, if the answer is 'no' - you set that digit to 0.

For example: I fix the second digit, so the list is:
{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31}
If the user answers 'yes', I know the number is of the form xxx1x, if 'no' then number is of the form xxx0x.
Repeat for every binary digit.

There's a whole hell of things you can do to optimize such a thing, but I'll write more once I see some code.

I solved it :)

This question has already been answered. Start a new discussion instead.