How can I make a random response generator?

Pages: 12
alright, thanks a bunch man.
Alright, one LAST question. It says that it was expecting a ; before string constant, I might just be blind, but what is wrong with this?

cout <<"What is your favorite artist?";
getline (cin, mystr);
if (mystr == "none")
{
cout <<" All right then, that's fine.";
}
else
{
cout << enjoydontenjoyartist [rand() %2] " listening to" << mystr ".";
}
cout << enjoydontenjoyartist [rand() %2] " listening to" << mystr ".";

Should be
cout << enjoydontenjoyartist [rand() %2] << " listening to" << mystr ".";
still doesn't work. Apparently it's missing a ; or something?
post you entire code inside of the [code][/code] tags

and post your compiler errors within the [quote][/quote] tags
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include <iostream>
#include <string>
#include <ctime>
#include <stdlib.h>
using namespace std;

int main ()
{
    srand(time(0));
    std::string mystr;
    std::string possibleanswers[2] = {"well", "not too bad"};
    std::string favoritecolor [8] = {"Red", "Blue", "Yellow", "Green", "Black", "Brown", "Gray", "Pink"};
    std::string likedislikemovie [2] = {"liked", "didn't like"};
    std::string favoriteshow [8] = {"The Walking Dead", "The Killing", "NCIS", "CSI", "The Big Bang Theory", "How I Met Your Mother", "Glee", "Breaking Bad"};
    std::string enjoydontenjoyartist [2] = {" I enjoy", "I don't enjoy"};
    std::cout <<"What is your name?";                    //name
    getline (cin, mystr);
    std::cout <<"Hello " <<  mystr  << ", nice to meet you. My name is Victor.";
    std::cout <<" How are you today?";                  //how are you
    getline (cin, mystr);
    if (mystr == "good")
    {
        std::cout <<"That is good.";
    }
    else if (mystr == "bad")
    {
        std::cout <<"That isn't good.";
    }

    else
    {
        std::cout <<"That's interesting.";
    }
    getline (std::cin, mystr);
    if (mystr == "you?")
    {
       std::cout <<"I am " << possibleanswers[rand() %2];
       std::cout <<". What is your favorite TV show?";
    }
    else
    cout <<"What is your favorite TV show?";        //TV show
    getline (cin, mystr);
    cout << favoriteshow[rand() %8] <<" is my favorite TV show.";
    cout <<" What is your favorite color?";             //color
    getline (cin, mystr);
    if (mystr == "red")
    {
        cout <<"I like red.";
    }
    else if (mystr == "blue")
    {
        cout <<"I enjoy the color blue.";
    }
    else  if (mystr == "yellow")
    {
        cout <<"Yellow is cool.";
    }
    else if (mystr == "brown")
    {
        cout <<"Brown is a gross color.";
    }
    else if (mystr == "black")
    {
        cout <<"Black is very cool.";
    }
    else if (mystr == "gray" or "grey")
    {
        cout <<"I don't like " << mystr << ".";
    }
    else if (mystr == "purple")
    {
        cout <<"Purple isn't a bad color.";
    }
    else if (mystr == "pink")
    {
        cout <<"Pink is an okay color.";
    }
    else if (mystr == "none")
    {
        cout <<"Oh, well that's fine.";
    }
    getline (cin, mystr);
    if (mystr == "you?")
    {
        cout << favoritecolor [rand() %8] <<" is my favorite color.";
        cout <<" What grade are you in?";
    }
    else
    cout <<" What grade are you in?";            //grade
    getline (cin, mystr);
    if (mystr == "none")
    {
        cout <<"That is interesting.";
    }
    else
    {
          cout <<"Oh, " << mystr << " grade. That is cool. ";
    }
    cout <<"How old are you?";                    //age
    getline (cin, mystr);
    cout <<"You are " << mystr << " years old.";
    getline (cin, mystr);
    if (mystr == "you?")
    {
        cout <<"I am a few weeks old. \n";
        cout <<"Do you have any siblings? If you do, what kind?";
    }
    else
    cout <<" Do you have any siblings? If you do, what kind?";
    getline (cin, mystr);
    if (mystr == "no")
    {
        cout <<"Oh well.";
    }
    else
    {
        cout <<"That is interesting. You have " << mystr << ".";
    }
    getline (cin, mystr);
    if (mystr == "you?")
    {
        cout <<"Yes. I have one brother, named Maxwell.";
        cout <<"What is your favorite sport?";
    }
    else
    cout <<" What is your favorite sport?";          //sports
    getline (cin, mystr);
    if (mystr == "baseball")
    {
        cout <<"I like baseball";
    }
    else if (mystr == "basketball")
    {
        cout <<"I like basketball too!";
    }
    else if (mystr == "soccer")
    {
        cout <<"Soccer is a cool sport.";
    }
    else if (mystr == "hockey")
    {
        cout <<"Hockey is pretty cool.";
    }
    else if (mystr == "tennis")
    {
        cout <<"Tennis is a cool sport!";
    }
    else if (mystr == "swimming")
    {
        cout <<"That is cool. I don't like water though";
    }
    else if (mystr == "football")
    {
        cout <<"Football is a dumb sport for Texans.";
    }
    else if (mystr == "The Hunger Games")
    {
        cout <<"That's a bloody nice sport, mate!";
    }
    else if (mystr == "diving")
    {
        cout <<"I don't like" << mystr << ". I don't like water.";
    }
    else if (mystr == "skiing")
    {
        cout <<"Skiing is cool. I just don't like the cold.";
    }
    else if (mystr == "shooting")
    {
        cout <<"I enjoy " << mystr <<". The noise can get annoying though.";
    }
    else if (mystr == "track and field")
    {
        cout <<"I enjoy " << mystr << ".";
    }
    else if (mystr == "golf")
    {
        cout <<"Golf is a boring sport to watch.";
    }
    else if (mystr == "wrestling")
    {
        cout <<"I don't like wrestling.";
    }
    else if (mystr == "none")
    {
        cout <<"Oh, well that's fine.";
    }
    else
    {
        cout <<"Oh. That's cool.";
    }
    cout <<" What kind of music do you like?";          //music
    getline (cin, mystr);
    if (mystr == "rock")
    {
        cout <<"I like rock music too!";
    }
    else if (mystr == "metal")
    {
        cout <<"Metal is amusing!";
    }
    else if (mystr == "country")
    {
        cout <<"I don't like country.";
    }
    else if (mystr == "jazz")
    {
        cout <<"Jazz is pretty chill.";
    }
    else if (mystr == "rap")
    {
        cout <<"I don't like rap much.";
    }
    else if (mystr == "hip hop")
    {
        cout <<"I'm indefferent on hip hop";
    }
    else if (mystr == "dubstep")
    {
        cout <<"I don't like dubstep too much.";
    }
    else if (mystr == "gospel")
    {
        cout <<"Uh, I don't like gospel at all.";
    }
    else if (mystr == "dance")
    {
        cout <<"I like dancing as well";
    }
    else if (mystr == "none")
    {
        cout <<"Oh, well that's okay.";
    }
    else
    {
        cout <<"Oh, that's cool.";
    }
    cout <<"What is your favorite artist?";
    getline (cin, mystr);
    if (mystr == "none")
    {
        cout <<" All right then, that's fine.";
    }
    else
    {
        cout << enjoydontenjoyartist [rand() %2] << " listening to" << mystr ".";
    }



C:\Users\Alex\Desktop\names!.cpp: In function 'int main()':
C:\Users\Alex\Desktop\names!.cpp:248: error: expected ';' before string constant
cout << enjoydontenjoyartist [rand() %2] << " listening to" << mystr ".";

I don't know how I didn't catch this, but it should be
cout << enjoydontenjoyartist [rand() %2] << " listening to" << mystr << ".";
oh wow, thanks. I knew it would be some small detail.
So for I have the random responses.
 
randomquestion[rand() %4]


Is there a way that I can identify the random question? Like:

1
2
3
4
5
6
7
8
9
randomquestion[rand() %4]
if (randomquestion == "Question 1")
{
     cout <<" this is question 1";
}
else if (randomquestion == "Question 2")
{
    cout <<" This is question 2";
}
There is a few ways to do this.
1)
1
2
3
4
int randomquestion = rand() % 4;
if (randomquestion == 0)
   cout << "Question 1";
// And so on 


2)
1
2
string questions[] = {"Question 1", "Question 2", "Question 3", "Question 4"};
cout << questions[rand() % 4];
Topic archived. No new replies allowed.
Pages: 12