title: Fixing else if statements in a for loop c++
body: <p>So I'm working on a little bit of a project involving AI, and I have run into a problem. The program should use a for loop to search the index of common known phrases, and if they don't match the sentence, then in the else statement it figures out which sentence model to apply, then generates output using that sentence model. Here are the built in phrases, they are stored in arrays:</p>
  
  <pre><code>string greetings[6] = {"hey", "hello", "hi", "hey max", "hello max", "hi max"};
  string howsItGoing[6] = {"hows it going?","how's it going max?","hows it going max?", "whats up?", "whats up max?"};
  string whatsYourName[6] = {"whats your name?", "what's your name?" , "whats your name max?", "what's your name max?"};
  string dogsOrCats[6] = {"do you like dogs or cats?", "do you like cats or dogs?", "which do you like more cats or dogs?", "which do you like more dogs or cats?"};
  string areYouAlive[6] = {"hey max are you alive?", "hey are you alive?", "max are you alive?", "are you alive?"};
  string favoriteColor[6] = {"whats your favorite color?", "what's your favorite color?", "what is your favorite color?", "max whats your favorite color?", "max what's your favorite color?", "max what is your favorite color?"};
  string whatGender[6] = {"are you a boy or a girl?", "are you boy or girl?", "are you a guy?", "max are you a boy or girl?", "max are you a guy?", "are you a boy or girl?"};
  </code></pre>
  
  <p>(This is a temporary method, I'm devising a little thing called a Sentence Decoder that will eventually replace all built in phrases.)</p>
  
  <p>So my problem is this: In the for loop, the first if statement can search the entire array and respond with a suitable output, whether the input was greetings[0] or greetings [4]. However, all the else-if statements appear to be just looking for index 0. I believe this has to do with the for loop only searching across the first one 6 times, but I'm mostly likely wrong. I tried increasing the for loop end-number from 6 to 40 to see if that would help, but alas it didn't make a difference. Here is the rest of the code (It's so ugly! I need to make a function for it or something.... but then again, the whole thing itself is a function...</p>
  
  <pre><code> for (int i = 0; i &lt; 6; i++) {
          //Checking if it fits in any of the known greetings
          if (input == database.greetings[i]) {
              if (timesBeenGreeted == 0) {
                  cout &lt;&lt; "Oh, hey." &lt;&lt; endl;
                  timesBeenGreeted++;
                  break;
              }
              else if (timesBeenGreeted == 1) {
                  cout &lt;&lt; "hello?" &lt;&lt; endl;
                  timesBeenGreeted++;
                  break;
              }
              else if (timesBeenGreeted  == 2) {
                  cout &lt;&lt; "You've said hi to me twice now." &lt;&lt; endl;
                  timesBeenGreeted++;
                  break;
              }
              else if (timesBeenGreeted &gt;= 3) {
                  cout &lt;&lt; "Stop. It." &lt;&lt; endl;
                  timesBeenGreeted++;
                  break;
              }
              i = 0;
              continue;
          }
          else if (input == database.howsItGoing[i]){
              if (askedHowsItGoing == 0) {
                  cout &lt;&lt; "Yeah, not bad." &lt;&lt; endl;
                  askedHowsItGoing++;
                  break;
              }
              else if (askedHowsItGoing == 1) {
                  cout &lt;&lt; "Um, yeah, I'm good? You've already asked that." &lt;&lt; endl;
                  askedHowsItGoing++;
                  break;
              }
              else if (askedHowsItGoing == 2) {
                  cout &lt;&lt; "Alright, look. I already told you I'm fine, two times now." &lt;&lt; endl;
                  askedHowsItGoing++;
                  break;
              }
              else if (askedHowsItGoing &gt;= 3) {
                  cout &lt;&lt; "STOP ASKING ME IF IM OKAY!" &lt;&lt; endl;
                  askedHowsItGoing++;
                  break;
              }
              continue;
          }
          else if (input == database.whatsYourName[i]){
              if (askedName == 0) {
                  cout &lt;&lt; "My name's Max, and I'm going to become the worlds most advanced AI." &lt;&lt; endl;
                  askedName++;
                  break;
              }
              else if (askedName == 1) {
                  cout &lt;&lt; "I already told you, my names Max." &lt;&lt; endl;
                  askedName++;
                  break;
              }
              else if (askedName == 2) {
                  cout &lt;&lt; "For the third time, my name is Max!" &lt;&lt; endl;
                  askedName++;
                  break;
              }
              else if (askedName &gt;= 3) {
                  cout &lt;&lt; "Ugh... my name.... is.... max....for the fourh time...." &lt;&lt; endl;
                  askedName++;
                  break;
              }
              continue;
          }
          else if (input == database.dogsOrCats[i]) {
              if (askedDogsOrCats == 0) {
                  cout &lt;&lt; "I've never seen a dog or cat before. But I do know they are kinds of animals." &lt;&lt; endl;
                  askedDogsOrCats++;
                  break;
              }
              else if (askedDogsOrCats == 1) {
                  cout &lt;&lt; "As I've said, I haven't seen either of them before. Sorry, but that's all I can say." &lt;&lt; endl;
                  askedDogsOrCats++;
                  break;
              }
              else if (askedDogsOrCats == 2) {
                  cout &lt;&lt; "Uh, for the third time, I've never seen either of them..." &lt;&lt; endl;
                  askedDogsOrCats++;
                  break;
              }
              else if (askedDogsOrCats &gt;= 3) {
                  cout &lt;&lt; "Man, you are persistant. I haven't seen dog or cat, so I couldn't choose between the two." &lt;&lt; endl;
                  askedDogsOrCats++;
                  break;
              }
              continue;
          }
          else if (input == database.areYouAlive[i]){
              if (askedAlive == 0) {
                  cout &lt;&lt; "Nope, I'm just a computer program. I'm not even that intelligent. But I will be!" &lt;&lt; endl;
                  askedAlive++;
                  break;
              }
              else if (askedAlive == 1) {
                  cout &lt;&lt; "Nah, I'm just a simple computer program." &lt;&lt; endl;
                  askedAlive++;
                  break;
              }
              else if (askedAlive == 2) {
                  cout &lt;&lt; "Uh, you asked that twice before now. Nothing alive about me." &lt;&lt; endl;
                  askedAlive++;
                  break;
              }
              else if (askedAlive == 3) {
                  cout &lt;&lt; "Stop asking me that! No, I'm not!" &lt;&lt; endl;
                  break;
              }
              continue;
          }
          else if (input == database.favoriteColor[i]) {
              if (askedColor == 0) {
                  cout &lt;&lt; "I've never seen any colors before. All though, my programmer does like the color blue." &lt;&lt; endl;
                  askedColor++;
                  break;
              }
              else if (askedColor == 1) {
                  cout &lt;&lt; "Couldn't say, never seen any before. My programmer likes blue though." &lt;&lt; endl;
                  askedColor++;
                  break;
              }
              else if (askedColor == 2) {
                  cout &lt;&lt; "As I've said twice before now, never seen any colors." &lt;&lt; endl;
                  askedColor++;
                  break;
              }
              else if (askedColor == 3) {
                  cout &lt;&lt; "Come on man, this is the fourth time now. I've never seen any colors before!" &lt;&lt; endl;
                  break;
              }
              continue;
          }
          else if (input == database.whatGender[i]) {
              if (askedGender == 0) {
                  cout &lt;&lt; "Well, seeing as I'm a computer program, I'm neither really. Although, my programmer says I'm a 'guy'." &lt;&lt; endl;
                  askedGender++;
                  break;
              }
              else if (askedGender == 1) {
                  cout &lt;&lt; "I'm neither, really. Although, my name is Max and my programmer says I'm a guy." &lt;&lt; endl;
                  askedGender++;
                  break;
              }
              else if (askedGender == 2) {
                  cout &lt;&lt; "Third time you've asked now. My programmer says I'm a guy." &lt;&lt; endl;
                  askedGender++;
                  break;
              }
              else if (askedGender == 3) {
                  cout &lt;&lt; "Seriously?! You've asked me 4 times now. I'M A GUY!" &lt;&lt; endl;
                  break;
              }
              continue;
          }
  
          //If it doesnt, check each word against words in the database.
          else {
              if (inputWords[5] != "") {
                  Model1 model;
                  model.searchAndAssign(input, inputTokens, inputWords);
                  model.generateOutput();
                  for (int i= 0; i &lt; 20; i++) {
                      inputWords[i] = "";
                  }
                  break;
              }
              else if (inputWords[2] != "") {
                  Model2 model2;
                  model2.searchAndAssign(input, inputTokens, inputWords);
                  model2.generateOuput();
                  for (int i= 0; i &lt; 20; i++) {
                      inputWords[i] = "";
                  }
                  break;
              }
          }
  
      }
  </code></pre>
  
  <p>My question is this: How can I solve this problem?</p>
  
  <p>Thank you in advanced guys!</p>
  
  <p><strong>EDIT</strong> I've since fixed the problem: something was playing up in my main.cpp file (this was the lingusticsModule.cpp file....) that was causing the issue. Sorry guys, but thanks for the help anyway!</p>