I am writing a program for a magic 8ball. I believe that I have everything I need with the exception of when I go to compile and run, I receive an error message stating that srand is not declared. I tried adding #include <cstdlib> to the header files, and that just gave me a different error. What am I missing? Thanks!
#include <iostream>
#include <string>
#include <ctime>
usingnamespace std;
int main ()
{
string getAnswer(string m8Ball[], int nAnswers);
//define a constant that represents how many answers are in your array (at least 8)
constint SIZE = 8;
//declare and initialize an array of strings, representing possible answers from the 8-ball
string m8ball[SIZE]{ "Certainly","Yes","Most Likely","Perhaps yes","Try again","Ask later","Don't do it", "No" };
srand((unsignedint)time(NULL));
//loop and ask the user to enter a question or enter "x" to stop
while (true)
{
//use getline to get the question
string question;
cout << "What is your question? (Enter 'x' to exit)" << endl;
getline(cin, question);
if (question.compare("x") == 0)
break;
//call getAnswer with your array and number of possible answers to get an answer
string answer = getAnswer(m8ball, SIZE);
//output the answer
cout << answer << endl << endl;
}
}