My first Computer Game/ Math Trick

 

 

Write code that will play the computer game that is explained below.

 

Click to see an example of how this math game will look when we play it.

 

How did that work?  Here is the trick:

 

After the user gives the first five digit number, subtract 2 from the number, and place a 2 in front of the number.  This is the final sum.

 

Each other time that the user gives a five digit number, give your number as follows: compute the difference of each digit of the user’s number with 9, and that is the number you will give.  For example, if the user gives the number 12121, your number will be 87878 (so that when your number and the user’s number is added, the sum will be 99999).

 

The total sum at the end will be 99999 + 99999 (which is 199998, which is 2 less than 200,000, for the four numbers) + the first number that the user chose!  That was easy to compute once we had the first number!

 

How do you program this?  Here is a step-by-step approach to solve this problem.

 

1)   ask user for name

2)   print message describing game

3)   ask user for first number

4)   compute and print final sum

5)   ask user for second number

6)   compute and print next number

7)   ask user for next number

8)   compute and print next number

9)   print final message….

 

If you prefer to write code for your own favorite math trick, that is fine too!