I've been writing a very simple chatbot but I'm stuck on generating random responses. I'm attempting to generate a random number between 1 and 5, and each number corresponds to a response in a switch statement. Here's my code:
#include <iostream>
#include <string>
#include <cstdlib>
usingnamespace std;
int main()
{
srand() = time(NULL);
string name = "hat is your name";
string userName = "USER";
size_t found;
while(true)
{
string input;
string inputPrev = input;
input = "";
cout << userName << ": ";
getline(cin,input);
cout << "MARTY: ";
found = input.find(name);
if(found != string::npos)
{
int random = rand();
while(random < 1 || random > 5)
{
random = rand();
}
switch(random)
{
case 1:
cout << "My name is Marty.\n";
case 2:
cout << "My name's Marty.\n";
case 3:
cout << "The name's Marty.\n";
case 4:
cout << "You can call me Marty.\n";
case 5:
cout << "Call me Marty.\n";
}
}
else
{
cout << "I don't understand.\n";
}
}
return 0;
}
However, when compiling in g++ on Ubuntu, I get this error message:
marty.cpp:8:11: error: too few arguments to function ‘void srand(unsigned int)’
Please keep in mind that I don't know exactly what I'm doing. I'm basing the random number generating code off of various tutorials. So what's wrong? Thanks in advance for your assistance!