Prog 2: TwentyFour

Write a program in C to play the game of Twenty Four.  The way the game works is that 4 digits are chosen, and the user must choose a combination of mathematical operators (+,-,/,*) to be applied to those numbers to yield the number 24.  You will write your program in stages as described below, where the number of points for each of the two sections is shown:

Stage 1 (20 points):

The first stage allows users to solve a single puzzle.   Running this first stage should look like the following, where user input is shown in bold:

Author: Dale Reed  Program: #2, TwentyFour  TA: Aaron Swartz, Th 4-5  Jan 28, 2013  Welcome to the game of TwentyFour.  Using each of the four numbers shown below exactly once, combining them somehow with the basic mathematical operators (+,-,*,/) to yield the value twenty-four.    The numbers to use are: 3, 9, 4, 1     Enter the three operators to be used (+,-,*, or /): *-+ 3.0 * 9 is: 27.0 27.0 - 4 is: 23.0 23.0 + 1 is 24.0  Well done, genius!   Would you like to play again (Y/N): N  Thanks for playing.  Exiting program...

The four numbers chosen to be presented to the user should randomly chosen to be one of the following:

     8         5         7         4          9         8           5   1     1   1     8   8     9   1      2   2     6   4           8         6         2         3          5         2  

If the user indicates that they do want to try again, the program should again randomly choose one of the 6 sets of numbers and display them:

The numbers to use are: 3, 9, 4, 1 

...

Stage 2 (35 points):

The second stage generates all 3,185 possible solutions and then chooses one at random, which gets presented to the user.   Running this second stage should look like the following, where only the first and last chunks of possible solutions are displayed:

Below is an excerpt of the output from running this program.  User input is shown in bold

Author: Dale Reed  Program: #2, TwentyFour  TA: Aaron Swartz, Th 4-5  Jan 28, 2013  Welcome to the game of TwentyFour.  Using each of the four numbers shown below exactly once, combining them somehow with the basic mathematical operators (+,-,*,/) to yield the value twenty-four.    *** Start Debug Display *** All possible solutions are: 1: 1+1+1*8 2: 1+1+2*6 3: 1+1*2*6 4: 1*1+2*8 5: 1/1+2*8 6: 1+1*3*4 7: 1*1+3*6 8: 1/1+3*6 9: 1-1+3*8 10: 1*1*3*8 11: 1/1*3*8 12: 1+1*4*3 13: 1+1+4*4 14: 1-1+4*6 15: 1*1*4*6  ... all lines are not shown here, but should be in your program ... 3174: 9+9-6*2 3175: 9-9+6*4 3176: 9/9*6*4 3177: 9+9/6*8 3178: 9+9+7-1 3179: 9/9+7*3 3180: 9+9+8-2 3181: 9-9+8*3 3182: 9/9*8*3 3183: 9+9*8/6 3184: 9+9+9-3 3185: 9*9-9/3 Puzzle to choose is #3176: 9/9*6*4 *** End Debug Display ***

The numbers to use are: 9, 9, 6, 4     Enter the three operators to be used (+,-,*, or /): /** 9.0 / 9 is: 1.0 1.0 * 4 is: 4.0 4.0 * 6 is 24.0  Well done, genius!   Would you like to play again (Y/N): N  Thanks for playing.  Exiting program...

Running the program again could look like the following:

Author: Dale Reed  Program: #2, TwentyFour  TA: Aaron Swartz, Th 4-5  Jan 28, 2013  Welcome to the game of TwentyFour.  Using each of the four numbers shown below exactly once, combining them somehow with the basic mathematical operators (+,-,*,/) to yield the value twenty-four.    *** Start Debug Display *** All possible solutions are: 1: 1+1+1*8 2: 1+1+2*6 3: 1+1*2*6 4: 1*1+2*8 5: 1/1+2*8 6: 1+1*3*4 7: 1*1+3*6 8: 1/1+3*6 9: 1-1+3*8 10: 1*1*3*8 11: 1/1*3*8 12: 1+1*4*3 13: 1+1+4*4 14: 1-1+4*6 15: 1*1*4*6  ... 3174: 9+9-6*2 3175: 9-9+6*4 3176: 9/9*6*4 3177: 9+9/6*8 3178: 9+9+7-1 3179: 9/9+7*3 3180: 9+9+8-2 3181: 9-9+8*3 3182: 9/9*8*3 3183: 9+9*8/6 3184: 9+9+9-3 3185: 9*9-9/3 Puzzle to choose is #910: 3*9-4+1 *** End Debug Display ***  The numbers to use are: 3, 9, 4, 1     Enter the three operators to be used (+,-,*, or /): *-+ 3.0 * 9 is: 27.0 27.0 - 4 is: 23.0 23.0 + 1 is 24.0  Well done, genius!   Would you like to play again (Y/N): Y

*** Start Debug Display *** All possible solutions are:   1. 1+1+1*8   2. 1+1+2*6   3. 1+1*2*6   4. 1*1+2*8   5. 1/1+2*8   6. 1+1*3*4   7. 1*1+3*6   8. 1/1+3*6   9. 1-1+3*8  10. 1*1*3*8  11. 1/1*3*8  12. 1+1*4*3  13. 1+1+4*4  14. 1-1+4*6  15. 1*1*4*6  ... 3174: 9+9-6*2 3175: 9-9+6*4 3176: 9/9*6*4 3177: 9+9/6*8 3178: 9+9+7-1 3179: 9/9+7*3 3180: 9+9+8-2 3181: 9-9+8*3 3182: 9/9*8*3 3183: 9+9*8/6 3184: 9+9+9-3 3185: 9*9-9/3 Puzzle to choose is #1657: 5+9+8+2  *** End Debug Display ***  The numbers to use are: 5, 9, 8, 2    Enter the three operators to be used (+,-,*, or /): +-** *** Sorry, that input is the wrong length.  Please retry. *** Enter the three operators to be used (+,-,*, or /): +-$ *** Sorry, invalid characters in input.  Please retry. *** Enter the three operators to be used (+,-,*, or /): */* 5.0 * 9 is: 45.0 45.0 / 8 is: 5.6 5.6 * 2 is: 11.2  Sorry, that was not correct.  The correct answer was: 5+9+8+2  Would you like to play again (Y/N): N  Thanks for playing.  Exiting program...

Other