Back to Challenge Set 7

Code Challenge: Magic 8 Ball

Difficulty  

divider

The Brief

What they asked for
I want the classic toy. You ask it a question, shake it, and
it gives you one of the standard answers at random. Some of
them are yes, some are no, and some are that annoying
non-answer.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • The question is never used for anything. Take it anyway, because the toy does — and because a program that does not ask does not feel like the toy.
  • Six answers is the usual number, and the customer has told you roughly what mix they want. Choosing the exact wording is yours.
  • Every answer has to be reachable. A program that can never print the sixth one has an off-by-one in its random range, and it will not tell you so.
  • Random.Shared.Next(1, 7) gives you 1 through 6. The second number is where it stops, not an answer you can get.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Take the question with Console.ReadLine(), then ignore it.
  2. Get a random whole number from 1 to 6 into a variable.
  3. Write six branches, one per answer — the chain shape from Activity 1.13.
  4. Run it ten times and check that all six answers can appear.

Sample Output

Sample Output
Ask me anything: Will I pass this class? [Enter]
Shaking...
Signs point to yes.

Ten runs will usually show you five of the six. If one answer has still not appeared after twenty, that is worth investigating rather than shrugging at — which is exactly the judgment Activity 1.16's Task 4 asked you to make.


Submit

Your requirements list and your program file, named cc-magic-8-ball.

Commence Challenge