title: I am getting a Divide by zero error but can't figure out why
body: <p>The error happens on this line:</p>
  
  <pre><code>return(rand()% sides + 1);
  </code></pre>
  
  <p>Here is my program:</p>
  
  <pre><code>//  main.cpp
  //  dcChecker
  //
  //  Created by Max Huber on 2/21/13.
  //  Copyright (c) 2013 S0URC3 Studioss. All rights reserved.
  //
  
  #include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  
  int rollDice(int);
  int diceCheck(int diceMod, int dci, int roll);
  void clearScreen();
  void pressEnter();
  void dcFunction();
  
  
  int main()
  {
      dcFunction();
      clearScreen();
      main();
  }
  
  // Roll a n sided die
  int rollDice(int sides)
  {
      //int gen;
  
      //create time variable
      time_t timer;
  
      //set time variable to current time in seconds
      time(&amp;timer);
  
      //seed random number generator using current time in seconds
      srand(timer);
  
      //generate random number
      //gen = (rand()% sides + 1);
  
      return(rand()% sides + 1);
  }
  
  // Check if the dice roll + modifier (if any) is greater than the check value
  int diceCheck(int diceMod, int dci, int roll)
  {
      if(roll + diceMod &gt;= dci)
      {
          return 0;
      }
      else
          return 1;
  }
  
  void clearScreen()
  {
      #ifdef WINDOWS
          std::system ( "CLS" );
  
      #else
          // Assume POSIX
          std::system ( "clear" );
      #endif
  }
  void pressEnter()
  {
      std::cin.sync();
      std::cout &lt;&lt; std::endl &lt;&lt; "Press ENTER to continue..." &lt;&lt; std::endl;
      std::cin.get();
  }
  
  void dcFunction()
  {
      //define variables
      int neededRoll;
      int diceMod;
      int sides;
      int roll;
  
      //get user inputs
      std::cout &lt;&lt; "How many sides: ";
      std::cin &gt;&gt; sides;
      std::cout &lt;&lt; "Enter needed roll: ";
      std::cin &gt;&gt; neededRoll;
      std::cout &lt;&lt; "Enter dice modifiers: ";
      std::cin &gt;&gt; diceMod;
  
      //store roll in variable so it can be gotten later
      roll = rollDice(sides);
  
      //check if your roll was better than the dice check
  
      //success check
      if(diceCheck(diceMod, neededRoll, roll) == 0)
      {
          std::cout &lt;&lt; "\nSUCCESS\n\n"
          &lt;&lt; "You rolled a " &lt;&lt; sides &lt;&lt; " sided die\n"
          &lt;&lt; "You rolled: " &lt;&lt; roll &lt;&lt; " + " &lt;&lt; diceMod &lt;&lt; " = " &lt;&lt; roll + diceMod &lt;&lt; "\n"
          &lt;&lt; "You needed: " &lt;&lt; neededRoll &lt;&lt; "\n";
      }
  
      //otherwise you fail
      else
      {
  
          std::cout &lt;&lt; "\nFAILURE!!!\n\n"
          &lt;&lt; "You rolled a " &lt;&lt; sides &lt;&lt; " sided die\n"
          &lt;&lt; "You rolled: " &lt;&lt; roll &lt;&lt; " + " &lt;&lt; diceMod &lt;&lt; " = " &lt;&lt; roll + diceMod &lt;&lt; "\n"
          &lt;&lt; "You needed: " &lt;&lt; neededRoll &lt;&lt; "\n";
      }
      pressEnter();
  }
  </code></pre>