Homework 3 - UMBC-CMSC104/General GitHub Wiki
Number Tricks
There are several number tricks that one can do -- these often consist of selecting a number at random, applying a variety of calculations to those numbers, and getting a particular output. We're going to implement a few of these for this assignment.
The assignment
Name the code for this assignment number_tricks.c.
I want you to implement the number tricks A, B, and C described on this page. The user will select which trick via a menu:
Welcome to homework 3!
Which number trick would you like to see?
1) Number trick A
2) Number trick B
3) Number trick C
Please make a selection:
If the user selects an invalid choice, be sure to check for it!
For A and B, I want you to show each step of the process. After all, it's not interesting to just show "7" or "2." for either one. For instance, for number trick A:
Please make a selection: 1
You have selected number trick A.
Please enter a number: 4
4 + 9 = 13
13 * 2 = 26
26 - 4 = 22
22 / 2 = 11
11 - 4 = 7
For number trick B:
Please make a selection: 2
You have selected number trick B.
Please enter a number: 9
9 + 5 = 14
14 * 3 = 42
42 - 9 = 33
33 / 3 = 11
11 - 9 = 2
For number trick C, the way it works is slightly different. You'll have to print out instructions to the user and then instruct them to provide you the result. Then, tell them what their original two numbers were:
1) Please select two numbers that are both less than 10.
2) Choose one of the numbers and multiply it by 5.
3) Add 7 to that result.
4) Multiply the resulting sum by 2.
5) Finally, add in the the number that you did not choose in step 2.
Tell me what your answer is: 101
Your numbers are 8 and 7. You selected 8 in step 2.
Submit the project by typing:
submit cs104_wilson hw03 number_tricks.c
Notes
- Don't forget to use the modulus operator. It will be helpful in number trick C.
- You'll have to use multiple variables to store different stages of each calculation.
- You can declare variables inside of if statements.
For example:
if(num == 1)
{
int step1;
int step2;
- Please reference the code here (classwork 3) and here (variables live demo).