#include <iostream>
#include <string>
#include <ctime>
usingnamespace std;
int main ()
{
string qString;
do {
srand((unsigned)time(0));
const string qNum[] {"Yes.", "No.", "Maybe.", "Outlook good.", "Outlook, not so good.",
"Question too hazy!", "Possible but not probable!", "I have no idea!", "Ask again later!"};
constint answer_count = sizeof(qNum)/sizeof(qNum[0]);
cout << "Ask me a yes or no question!" << endl;
cout << "Question: ";
string qString;
cin >> qString;
int rand_answer = rand() % answer_count;
cout << qNum[rand_answer] << endl;
} while (qString != "Goodbye");
return 0;
}
Sorry for all the questions, It may seem like I am 9, I am 15 male :p
#include <iostream>
#include <string>
#include <cstdlib> // for srand, rand
#include <ctime>
usingnamespace std;
int main ()
{
string qString;
do {
srand((unsigned)time(0));
const string qNum[] {"Yes.", "No.", "Maybe.", "Outlook good.", // fold
"Outlook, not so good.", "Question too hazy!",
"Possible but not probable!", "I have no idea!",
"Ask again later!"};
constint answer_count = sizeof(qNum)/sizeof(qNum[0]);
cout << "Ask me a yes or no question!" << endl;
cout << "Question: ";
//string qString; use the one on line 9
//cin >> qString;
getline(cin, qString); // use getline() so question can contain spaces!
int rand_answer = rand() % answer_count;
cout << qNum[rand_answer] << endl;
} while (qString != "Goodbye");
return 0;
}
Also, srand() should almost always be called just once, at the start of your program. And the const data doesn't need to be in the loop.
#include <iostream>
#include <string>
#include <cstdlib> // for srand, rand
#include <ctime>
usingnamespace std;
int main ()
{
srand((unsigned)time(0));
const string qNum[] {"Yes.", "No.", "Maybe.", "Outlook good.", // fold
"Outlook, not so good.", "Question too hazy!",
"Possible but not probable!", "I have no idea!",
"Ask again later!"};
constint answer_count = sizeof(qNum)/sizeof(qNum[0]);
string qString;
do {
cout << "Ask me a yes or no question!" << endl;
cout << "Question: ";
getline(cin, qString); // use getline() so question can contain spaces!
int rand_answer = rand() % answer_count;
cout << qNum[rand_answer] << endl;
} while (qString != "Goodbye");
return 0;
}