function call not working

writing a magic 8 ball program. menu selection 2 asks for user response which is then given a random response from the file included below. when I run the code it just repeats the # 2 question and menu infinitely. any idea what I'm doing wrong?

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
  #include <iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<ctime>

using namespace std;

void readFromfile(string filename, string response[], string category[], int& maxResponses);
void magicEight( string response[], string category[], int& maxResponses);
void sortBall (string filename, string response[], string category[], int& maxResponses);



int main (){

    bool done=false;
    int menu;
    const int MAXSIZE = 100;
    string  response[MAXSIZE], category[MAXSIZE], answer, categories;
    int size=0;
    while(!done){
        cout<<"Select one of the options below\n";
        cout<<"1. Read responses from file\n";
        cout<<"2. Play Magic 8 Ball.\n";
        cout<<"3. Print out responses and categories alphabetically\n";
        cout<<"4. Exit\n";

        cin>>menu;
        switch(menu){
            case 1 :
                cout<<"Read from file\n";
                readFromfile("answers.txt", response, category, size );
                break;
            case 2:
                cout<<"Play Magic 8 Ball\n";
                magicEight( response, category, size);
                break;
            /*case 3:
                cout<<"Print out responses alphabetically\n";
                sortBall ( "answers.txt", response, category, size);
                break;*/
            case 4:
                cout<<"You will now exit menu.\n";
                done=true;
                break;
            default:
                cout<<"Invalid option.\n";

        }
    }



    return 0;
}
void readFromfile(string filename, string response[], string category[], int& maxResponses) {
    string answer, cats;
    int i = 0, j = 0, k = 0;
    ifstream infile(filename);
    while (getline(infile, answer)) {
        if (answer.back() == '\r') {
            answer.pop_back();
        }
        getline(infile, cats);
        response[maxResponses]=answer;
        category[maxResponses]=cats;
        cout<<response[maxResponses]<<" "<<category[maxResponses]<<endl;

        maxResponses++;

    }
}
void magicEight( string response[], string category[], int& maxResponses) {
    string question;
    char reply;
    srand(time(0));
    int i = 0, j = 0, k = 0;
    //do{

    cout << "Hi! I am magic Eight ball, ask me a question.." << endl;
    cin>>question;

    int index= rand()%(maxResponses-1);

    cout<<response[index]<<endl;

file answers.txt
It is certain
positive
It is decidedly so
positive
Without a doubt
positive
Yes definitely
positive
You may rely on it
positive
As I see it, yes
positive
Most likely
positive
Outlook good
positive
Yes
positive
Signs point to yes
positive
Reply hazy try again
vague
Ask again later
vague
Better not tell you now
vague
Cannot predict now
vague
Concentrate and ask again
vague
Don't count on it
negative
My reply is no
negative
My sources say no
negative
Outlook not so good
negative
Very doubtful
negative 
First of all, I have no idea what you are trying to do here.

 
     int index= rand()%(maxResponses-1);


Since you only pass in size, which is zero, this is going to be a random number mod -1, which is always going to be zero.

Secondly, you don't need the boolean done variable in main. Just make your loop while(true) and in case 4, just do return 0.

I wasn't able to reproduce the error you said was happening when I ran the code in cpp.sh, so I'm not sure what you mean by "repeats question 2 and menu infinitely"
forgive me i'm new. was ahead in class then got sick with all this stuff and am trying to cram a semester into a week. instructor explained that the int index = rand()%(maxResponses-1) would take the max number of read in string and print out a random response.

this is what I get when I enter option 2
1
2
3
Play magic 8 ball
Hi! i am magic 8 ball , ask me a question..
would you like to play again


it skips to the end of the void function without user input at all.

for option 3
it skips to the menu right way
Your instructor is correct. However, look at your code and tell me what value maxResponses has every time the function is called.
Topic archived. No new replies allowed.