(Hint: The digit pattern is too large to store into any datatype we have learned to date so I am expecting that you will use a loop to print individual digits, rather than store the complete number in a variable.)

PROGRAM 6: Magic Number Game
Write a program that reads a magic number. Then start reading numbers, one-by-one. After each value, offer advice (higher or lower) to the player on how to win the game. If the magic number is entered, the player wins the game! If the player enters 5 numbers without entering the magic number, the player loses the game. Before the fifth number, spit out the words “Last Try!”.

Shown below is a sample program dialogue to help you build your program.

Gimme the magic number: 20
Gimme a starting number: 50
Lower
Next: 40
Lower
Next: 1
Higher
Next: 30
Lower
Next: 20
You Won The Game!

Gimme the magic number: 50
Gimme a starting number: 20
Higher
Next: 21
Higher
Next: 31
Higher
Next: 32
Higher
Last Try!
Next: 33
Sorry Charlie, You Lost The Game!

Gimme the magic number: 50
Gimme a starting number: 90
Lower
Next: 89
Lower
Next: 80
Lower
Next: 79
Lower
Last Try!
Next: 70
Sorry Charlie, You Lost The Game!

(Hint: This program is pretty complex with many different conditions to keep track of. I would recommend you write it first in C or Visual Basic and then translate your lines of code, one-by-one, into a assembly statements, just like our good friend mr. compiler does.)

Sample Solution

This question has been answered.

Get Answer