title: Need a better solution to a hackerrank challenge
body: <p>So I am new to competitive programming and I have been trying to solve this challenge for the past hour or so. I'm pretty sure my solution is overly complicated so can someone give me a better solution please? My code is pretty bad so if you can pls provide me with some feedback.</p>
  <p><em><strong>The challenge</strong></em></p>
  <p>You are given the day of the week for the first day of a month (M) (e.g. 1-Monday, 2-Tuesday, 3- Wednesday ...) and a date (D). You need to find the day of the week for the date given.</p>
  <p>Constraints:
  1&lt;=M&lt;=7
  1&lt;=D&lt;=31</p>
  <p>e.g.
  Input: 1 30
  Output: 2</p>
  <p>My (bad) code:</p>
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdio&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  int find_answer_for_more_than_7_days(int start,int day){
      cout&lt;&lt;day%7 + start - 1;
      return 0;
  }
  int find_answer_for_less_than_7_days(int start,int day){
      if ((start + day - 1)&gt;7)
          cout&lt;&lt;start+day - 8;
      else
          cout&lt;&lt; start + day  - 1;
      return 0;
  }
  int find_answer(int start, int day){
      if (day&gt;7)
          find_answer_for_more_than_7_days(start, day);
      else if (day&lt;7)
           find_answer_for_less_than_7_days(start,day);   
      return 0;
  }
  
  
  int main() {
      int m,d;
      cin&gt;&gt;m&gt;&gt;d;
      if (d!=1){
          if (d%7 == 0){
              if (m != 1)
                  cout&lt;&lt;m-1;
              else
                  cout&lt;&lt;7;
          }
          else{
              if (m == 1){
                      if (d&gt;7)
                          cout&lt;&lt;d%7;
                      else if (d&lt;7)
                          cout&lt;&lt; d;
                  }
              else if (m == 7){
                  if (d &gt; 7)
                      cout&lt;&lt;d - 7*(d/7) - 1;
                  else if (d&lt; 7)
                      cout&lt;&lt; d - 1;
              }
              else{
                  find_answer(m,d);
              }
              }
          }
      else
          cout&lt;&lt; m;
      return 0;
    }
  </code></pre>