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
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.
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
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.