Question
This is to be written in C++ and i use code blocks Convert the magic eight ball program from the arrays module to use a
This is to be written in C++ and i use code blocks
Convert the magic eight ball program from the arrays module to use a vector instead of an array. Be sure to do these things in your program:
use the push_back() function to initialize the array
modify the signature and prototype of the getAnswer() function
modify the code in the body of the getAnswer() function
remove any unneeded code, such as your constant for the number of answers
Here is the given code
#include
using namespace std;
string getAnswer (string m8Ball[], int nAnswers);
int main () { const int num = 12;
string array[num] = {"Yes of course", "without a doubt, yes", "you can count on it", "Forsure!", "Ask me later", "I'm not sure ", "I can tell you right now", " I'll tell you after my nap", "No way!", "I don't think so", " without a doubt, no", "the answer is clearly NO"};
srand((unsigned int) time (NULL));
while (1) { string userinput;
cout << "Enter the Question: " << " "; getline(cin, userinput);
if (userinput.compare ("x")==0) break; cout << "the magic ball says: "<< getAnswer(array, num) << " "; } } string getAnswer (string m8Ball[], int nAnswers) { int index = rand() % nAnswers;
return m8Ball[index];
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started