Prog 1: Guess Number

Change Log:

1/12 Output was changed to count the number of values that have duplicate digits, as announced 1/11 in class.  Output now also shows multiple runs of the program.  YouTube video was replaced to reflect the above change.

1/18 Program description changed to specify that reversing a number need not be in a function.  Shown in blue below.

1/19 Fixed further language that specified functions.  Shown in green below.

1/23 The instructions ask you to test all possible values between 1..1000.  Assume this does *not* include 1000.  My sample output below incorrectly starts at 0 rather than at 1, as it should.  For this reason we will accept a count value of either 279 (when starting at 1) or 280 (when starting at 0).

Write a program that interacts with the user, and predicts their final number! (This idea came from this YouTube video.)

Running your program should look like the following, where user input is shown in bold:

Author: Dale Reed  Program: #1, Guess Number  TA: Karla Templar, Tues 10  Jan 8, 2017   Welcome to the number guessing game!  If you concentrate, sometimes you can connect to the electrons in the computer!  Let's try it.  Think of a three digit number. (To make it harder, make the digits   all different from each other). Type in your number: 532   I'll help you with the math.  Lets randomize those digits by reversing them, and do a subtraction:    532  (The original number)   - 235  (The reversed digits)   =====     297    Press 'Y' to continue or 'X' to exit... y   Now lets again scramble the numbers by reversing them, and adding them this time:     297   + 792   =====       ?    Before you continue, take a look at my number guess written down on paper.    Press 'D' to display the answer or 'X' to exit... d Answer is 1089.    Press 'T' to test all possible combinations or 'X' to exit... x

Running the program again for a different input gives the following:

Author: Dale Reed  Program: #1, Guess Number  TA: Karla Templar, Tues 10  Jan 8, 2017   Welcome to the number guessing game!  If you concentrate, sometimes you can connect to the electrons in the computer!  Let's try it.  Think of a three digit number. (To make it harder, make the digits   all different from each other). Type in your number: 275   I'll help you with the math.  Lets randomize those digits by reversing them, and do a subtraction:    572  (The reversed digits)   - 275  (The original number)   =====     297    Press 'Y' to continue or 'X' to exit... y   Now lets again scramble the numbers by reversing them, and adding them this time:     297   + 792   =====       ?    Before you continue, take a look at my number guess written down on paper.    Press 'D' to display the answer or 'X' to exit... d Answer is 1089.    Press 'T' to test all possible combinations or 'X' to exit... x

Running the program again for input with duplicate digits gives the following:

Author: Dale Reed  Program: #1, Guess Number  TA: Karla Templar, Tues 10  Jan 8, 2017   Welcome to the number guessing game!  If you concentrate, sometimes you can connect to the electrons in the computer!  Let's try it.  Think of a three digit number. (To make it harder, make the digits   all different from each other). Type in your number: 424   *** All three digits are not different.  Exiting program...  Program ended with exit code: 0

Running the program again with a single digit input value again fails, since a single digit implicitly has two preceding zeros, which are duplicate digits:

Author: Dale Reed  Program: #1, Guess Number  TA: Karla Templar, Tues 10  Jan 8, 2017   Welcome to the number guessing game!  If you concentrate, sometimes you can connect to the electrons in the computer!  Let's try it.  Think of a three digit number. (To make it harder, make the digits   all different from each other). Type in your number: 9   *** All three digits are not different.  Exiting program...  Program ended with exit code: 0

Running the program again and this time going all the way through gives the following output.  Note that you can display the large table of output numbers just be printing the numbers and letting them wrap around the screen.  The width of your screen may result in the line wraps being different than what is shown below:

Author: Dale Reed  Program: #1, Guess Number  TA: Karla Templar, Tues 10  Jan 8, 2017   Welcome to the number guessing game!  If you concentrate, sometimes you can connect to the electrons in the computer!  Let's try it.  Think of a three digit number. (To make it harder, make the digits   all different from each other). Type in your number: 35   I'll help you with the math.  Lets randomize those digits by reversing them, and do a subtraction:    530  (The reversed digits)   -  35  (The original number)   =====     495    Press 'Y' to continue or 'X' to exit... Y   Now lets again scramble the numbers by reversing them, and adding them this time:     495   + 594   =====       ?    Before you continue, take a look at my number guess written down on paper.    Press 'D' to display the answer or 'X' to exit... D Answer is 1089.    Press 'T' to test all possible combinations or 'X' to exit... t For all numbers between 1..1000, the values that do not work are:    0   1   2   3   4   5   6   7   8   9  10  11  20  22  30  33  40  44  50  55  60  66  70  77  80  88 90  99 100 101 110 111 112 113 114 115 116 117 118 119 121 122 131 133 141 144 151 155 161 166 171 177 181 188 191 199 200 202 211 212 220 221 222 223 224 225 226 227 228 229 232 233 242 244 252 255 262 266  272 277 282 288 292 299 300 303 311 313 322 323 330 331 332 333 334 335 336 337 338 339 343 344 353 355  363 366 373 377 383 388 393 399 400 404 411 414 422 424 433 434 440 441 442 443 444 445 446 447 448 449  454 455 464 466 474 477 484 488 494 499 500 505 511 515 522 525 533 535 544 545 550 551 552 553 554 555  556 557 558 559 565 566 575 577 585 588 595 599 600 606 611 616 622 626 633 636 644 646 655 656 660 661  662 663 664 665 666 667 668 669 676 677 686 688 696 699 700 707 711 717 722 727 733 737 744 747 755 757  766 767 770 771 772 773 774 775 776 777 778 779 787 788 797 799 800 808 811 818 822 828 833 838 844 848  855 858 866 868 877 878 880 881 882 883 884 885 886 887 888 889 898 899 900 909 911 919 922 929 933 939  944 949 955 959 966 969 977 979 988 989 990 991 992 993 994 995 996 997 998 999

There are 280 values that do not work.    Thanks for playing!   

In the first step where you do the subtraction be sure to always put the largest number on the top.  You can watch a ~three-minute YouTube video of this program running.  Your program should handle any input between 1 and 999 and must do the calculations at the end to count how many values do not work (i.e. how many don't have three distinct digits, or that after the computation don't end up equaling 1089).

You need to know how to:

It is also helpful - though not essential - for you to break up your program using functions.  I suggest you write the program using the following steps, for the various amounts of credit shown:

Be sure to read the grading criteria on the course syllabus before turning in your program.  Turn in your program using Blackboard.  Multiple submissions are allowed, but only the most recent submission will be graded.