/* ask the user if they want to play? while the answer is yes Ask the user for their question Generate a random response print the question and response ask the user if they want to play again? To Generate a random response Generate a random number between 0 and 19, or 1 and 20 return the corresponding phrase */ #include #include using namespace std; int main() { string question, answer {"Yes"}; int dieRoll; char response; srand(time(nullptr)); cout << "Do you have a question for the magic 8-ball (Y-N)? "; cin >> response; cin.ignore(100,'\n'); response = toupper(response); while ('Y' == response) { cout << "Enter a question for the magic 8-ball: "; getline(cin,question); cout << endl; dieRoll = rand() % 12; cout << "The roll is " << dieRoll << endl; /* if (dieRoll == 0) { answer = "It is Certain"; } else if (dieRoll == 1) { answer = "It is decidedly so."; } else if (dieRoll == 2) { answer = "Reply hazy, try again."; } else if (dieRoll == 3) { answer = "Don't count on it."; } else { answer = "There is an error in the program."; } */ switch(dieRoll) { case 0: cout << "It is a 0" << endl; case 4: cout << "It is a 0 or 4" << endl; case 11: cout << "It is a 0 or 4 or 11" << endl; answer = "It is Certain"; break; case 1: case 5: case 10: answer = "It is decidedly so."; break; case 2: case 6: case 9: answer = "Reply hazy, try again."; break; case 3: case 7: case 8: answer = "Don't count on it."; break; default: answer = "There is an error in the program."; } cout << "Your question: \"" << question << "\"" << endl; cout << "The magic 8-ball says: " << answer << endl; cout << endl << endl; cout << "Do you have another question for the magic 8-ball (Y-N)? "; cin >> response; cin.ignore(100,'\n'); response = toupper(response); } cout << endl; cout << "Thank you for using the magic 8-ball" << endl; return 0; }