title: Runtime error: program has stopped responding
body: <p>My program is to calculate the price of resources based on the resources that their neighbors have.</p>
  
  <p>It compiles, but at run-time, it breaks and says that the program has stopped responding.</p>
  
  <p>Any help is greatly appreciated!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  class Resource{
      string resName;
      int amount;
      int price;
      public:
          void set_values(string resName, int amount, int price){resName=resName; amount=amount; price=price;};
          string get_name(){return resName;};
          int get_amount(){return amount;};
          int get_price(){return price;}; 
  };
  
  class State{
      string stName;
      Resource resources[5];
      public:
          void set_values(string stName){
              stName=stName;
              Resource r; 
              r.set_values(" ", 0, 0);
              for (int i=0; i&lt;5; i++){
                  resources[i] = r;
              }
          };
          string get_name(){return stName;};
          void addResource(string name, int amount, int price){
              Resource r;
              r.set_values(name, amount, price);
              for (int i=0; i&lt;5; i++){
                  if(resources[i].get_name() == " "){
                      resources[i] = r;
                  }
              }
          };
          Resource get_resource(string resource){
              for(int i=0; i&lt;5; i++){
                  if (resources[i].get_name() == resource){
                      return resources[i];
                  }
              }
          };
          bool checkForResource(string resource){
              for(int i=0; i&lt;5; i++){
                  if (resources[i].get_name() == resource){
                      return true;
                  }
              }
          }
  
  };
  
  class Area{
      State allStates[10][10];
      public:
          void initialize(){
              for (int i=0; i&lt;10; i++){
                  for (int j=0; j&lt;10; j++){
                      allStates[i][j].set_values(" ");    
                  }
              }   
          };
          void addState(string stateName){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == " ")
                          allStates[row][col].set_values(stateName);
                  }   
              }   
          };
          State get_state(string name){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == name)
                          return allStates[row][col];
                  }   
              }
          };
          void deleteState(string name){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == name)
                          allStates[row][col].set_values(" ");
                  }   
              }
          };
          void moveRowsSouth(){
              for(int z=0; z&lt;10; z++){
                  for(int y=10; y&gt;=1; y--){
                      allStates[y][z] = allStates[y-1][z];
                  }
                  allStates[0][z].set_values(" ");
              }
          };
          void moveColsEast(){
              for(int z=0; z&lt;10; z++){
                  for(int y=10; y&gt;=1; y--){
                      allStates[z][y] = allStates[z][y-1];
                  }
                  allStates[z][0].set_values(" ");
              }
          };
          void addNeighbor(string s1, string s2, string direction){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == s1)
                          if (direction == "North"){
                              if (row-1 &lt; 0){
                                  moveRowsSouth();
                              }
                              else {
                                  if (allStates[row-1][col].get_name() == " "){
                                      allStates[row-1][col] = get_state(s2);
                                      deleteState(s2);
                                  }
                                  else
                                      cout &lt;&lt; "Unable to add this neighbor. North is occupied.";
                              }
                          }
                          else if (direction == "South"){
                              if (allStates[row+1][col].get_name() == " "){
                                  allStates[row+1][col] = get_state(s2);
                                  deleteState(s2);
                              }
                              else
                                  cout &lt;&lt; "Unable to add this neighbor. South is occupied.";
  
                          }
                          else if (direction == "East"){
                              if (allStates[row][col+1].get_name() == " "){
                                  allStates[row][col+1] = get_state(s2);
                                  deleteState(s2);
                              }
                              else
                                  cout &lt;&lt; "Unable to add this neighbor. East is occupied.";
                          }
                          else if (direction == "West"){
                              if (col-1 &lt; 0){
                                  moveColsEast();
                              }
                              else {
                                  if (allStates[row][col-1].get_name() == " "){
                                      allStates[row][col-1] = get_state(s2);
                                      deleteState(s2);
                                  }
                                  else
                                      cout &lt;&lt; "Unable to add this neighbor. West is occupied.";
                              }
                          }
                  }   
              }
          };
          State getNeighborN(string s1){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == s1)
                          return allStates[row-1][col];
                  }   
              }
          };
          State getNeighborS(string s1){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == s1)
                          return allStates[row+1][col];
                  }   
              }
          };
          State getNeighborE(string s1){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == s1)
                          return allStates[row][col+1];
                  }   
              }
          };
          State getNeighborW(string s1){
              for (int row=0; row&lt;10; row++){
                  for (int col=0; col&lt;10; col++){
                      if (allStates[row][col].get_name() == s1)
                          return allStates[row][col-1];
                  }   
              }
          };  
  };
  
  int main()
  {
      Area a;
      a.initialize();
      ifstream infile;
      string command;
      infile.open ("proj2.txt", ifstream::in);
      while(!infile.eof()){
          infile &gt;&gt; command;
          if (command == "addState"){
              string stateName;
              infile &gt;&gt; stateName;
              a.addState(stateName);
          }
          else if (command == "addNeighbor"){
              string state1;
              string state2;
              string direction;
              infile &gt;&gt; state1;
              infile &gt;&gt; state2;
              infile &gt;&gt; direction;
              a.addNeighbor(state1, state2, direction);
          }
          else if (command == "addResource"){
              string state;
              string name;
              int amount;
              int price;
              infile &gt;&gt; state;
              infile &gt;&gt; name;
              infile &gt;&gt; amount;
              infile &gt;&gt; price;
              a.get_state(state).addResource(name, amount, price);
          }
          else if (command == "getPrice"){
              string state;
              string resource;
              int amount;
              infile &gt;&gt; state;
              infile &gt;&gt; resource;
              infile &gt;&gt; amount;
              State N = a.getNeighborN(state);
              State S = a.getNeighborS(state);
              State E = a.getNeighborE(state);
              State W = a.getNeighborW(state);
              int countOfNeigh = 0;
              bool stateHas = false;
              if (N.checkForResource(resource) == true) {
                  countOfNeigh++;
              }
              if (S.checkForResource(resource) == true) {
                  countOfNeigh++;
              }
              if (E.checkForResource(resource) == true) {
                  countOfNeigh++;
              }
              if (W.checkForResource(resource) == true) {
                  countOfNeigh++;
              }
              if (a.get_state(state).checkForResource(resource) == true) {
                  stateHas = true;
              }
              int price = 0;
              if ((stateHas = false &amp;&amp; countOfNeigh == 1) ||
                   (stateHas = true &amp;&amp; countOfNeigh == 0)){
                  price = a.get_state(state).get_resource(resource).get_price();
                  price = price+(price*.25);
              }
              else if (stateHas = true &amp;&amp; (countOfNeigh == 2 || countOfNeigh == 3)){
                  price = a.get_state(state).get_resource(resource).get_price();
              }
              else if (stateHas = true &amp;&amp; countOfNeigh == 4){
                  price = a.get_state(state).get_resource(resource).get_price();
                  price = price-(price*.1);
              }
              else if (stateHas = false &amp;&amp; countOfNeigh &gt; 1){
                  price = a.get_state(state).get_resource(resource).get_price();
                  price = price+(price*.1);
              }
              cout &lt;&lt; "The price for " &lt;&lt; amount &lt;&lt; " units of " &lt;&lt; resource &lt;&lt; " is " &lt;&lt; price &lt;&lt; ".";
          }
      }
  }
  </code></pre>