C++ Assignment 13
Magic 8 ball

This assignment asks you to write an application that replicates the classic Magic 8 Ball toy from the 1960’s. Your program (like the original 8 Ball) will not really pay any attention to the user’s question-it will simply take the question and discard it. Then it always gives one of several “canned” answers. The original Magic 8 Ball had the answers printed on the sides of two eight sided dice. These are the original answers:


outlook not so good       don't count on it         my sources say no
without a doubt           reply hazy, try again     it is certain
my reply is no            as I see it yes           most likely
you may rely on it        cannot predict now	
better not tell you now   very doubtful             outlook good	
yes definitely            concentrate and ask again

You may use these answers or make up your own.

string DisplayInputXY (int nX, int nY)

cin and cout don't work well with graphics, so for this assignment you will need to use a function DisplayInputXY which you can download from the class website by clicking on the link. Try putting the following code in a main function of a graphics program to test out how the function works. (Of course, you will also need to copy the function from the website into your program for this to work!)

string sQuestion;
do
{
   sQuestion = DisplayInputXY(320,260);
   cleardevice();
}while(sQuestion != "quit");

Arrays in C++

An array is a collection of data all of the same type that is accessed by index. For this assignment you are required to use an array of strings to store the answers. You can declare and intialize an array of apstrings with code like:
string saAnswers[] = {"yes", "no", "maybe" };
Remember that arrays in C++ are zero based so,
cout<<saAnswers[1]<<endl;
would display “no” . To display the same thing using outtextxy from winbgim.h, you would need to convert the C++ string to an "old fashioned" C string with .c_str().
outtextxy(320,240,saAnswers[1].c_str());

Random Numbers in C++

The rand() function from stdlib.h returns a "pseudo-random" number between 0 and some very large number. It's usually used with modulus to "scale" it to a usable value. The following code will display a random number that can be 0, 1, 2, 3, 4, 5, or 6.
cout<<rand()%7<<endl;
The numbers are called "pseudo-random" because they aren't really random, they are just looked up in a table. To insure that your program always starts from a different place in the table, put the following code near the top of the main function:
srand(time(NULL));
This is called "seeding the random number generator" and it insures that the program will look up a different sequence of random numbers each time it runs. IMPORTANT: Do NOT seed the random generator more than once!

Program Requirements

Your program will need at least three functions besides main and DisplayInputXY():

void DrawBall();       //draws the picture of the 8 ball
void DisplayAnswer();  //Displays a random answer to the screen using outtextxy()
void Prompt();         //Displays instructions to the user