help with this?

mixhi4ever (14)
The classic toy the Magic 8 Ball make predictions about the future if you asked it a yes/no question. Write a C++ program that simulates a magic 8 ball (you need 5 different prediction statements). Your program should choose which prediction to make using a switch statement based on a randomly generated integer. To generate a random integer between 1 and 5, you need the following code:


#include <time.h>
put this line at the top of your program file right after you include <iostream> and before the namespace line

srand(time(NULL));


rand() % 5 + 1;


What would be the input for for the user?? I can't ask them to enter a number.

Thanks in advance and feel free to give me tips.
whitenite1 (751)
@mixhi4ever

All you need to do, is let the user input a question. Then jump to the case in the switch, that matches your random number answer.
Hope this is enough to get you on your way...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <string>

string question;
int answer;
cout << "What would you like to ask the Magic Ball, that knows all ???" << endl;
getline(cin, question);

answer = rand() % 5 + 1;

switch (answer)
{
case 1:
cout << "Not at this time.." << endl;
break;
case 2:
etc....


Last edited on
Registered users can post here. Sign in or register to post.