not declared in scope, beginners snail racing game
<p>Ok, I googled and found some answers here on this site regarding this, but the answers are to different for me to really do anything with them, so I ask again and hope for the best. </p>

<p>I got the following errors in g++; </p>

<p>snailrace.cpp: In function ‘int race(int, int)’:</p>

<p>snailrace.cpp:101:21: error: ‘rand’ was not declared in this scope</p>

<p>snailrace.cpp:123:3: error: a function-definition is not allowed here before ‘{’ token</p>

<p>snailrace.cpp:128:3: error: expected ‘}’ at end of input</p>

<p>I think I will be able to solve everything except the "snailrace.cpp:101:21: error: ‘rand’ was not declared in this scope" I tried EVERYTHING and it wont help! 
How do I solve that!? It is driving me insane. 
Thanks!</p>

<pre><code>//The snail race.

#include &lt;iostream&gt;
#include &lt;ctime&gt;

//Function declaration.
int race(int,int); 
void race(void);
int menu(void);
int placebet(int);
void init(void);

//Varibles 
int money = 200; 

//the main function
int main(void)
{
  using std::cout; 

  init();
  int user_respons;

  cout &lt;&lt; "Welcome to the snail race!\n"; 

  while(user_respons = menu())
  {

    switch(user_respons)
    {
      case 1:
      case 2:
      case 3: 
    ::money +=
    race(placebet(user_respons), user_respons); 
    break;

      case 4: //The user did not bet
    race();
    break; 
  }
}
return 0; 

}

//Display user menu and sends user selection to the main function
int menu( void )
{
  using std::cout;
  using std::cin; 

  int user_respons;

  cout &lt;&lt; "You have " &lt;&lt; money &lt;&lt; " USD.\n";

  do
  {
    cout &lt;&lt; "Race Menu: \n\n"
     &lt;&lt; "1) Bet on snail 1\n"
     &lt;&lt; "2) Bet on snail 2\n"
     &lt;&lt; "3) Bet on snail 3\n"
     &lt;&lt; "4) Do not bet, just watching"
     &lt;&lt; "0) Leave the race"; 

    cin &gt;&gt; user_respons;
  }
  while(user_respons &lt; 0 &amp;&amp; user_respons &gt; 4);
  return user_respons;
}

//Decide how much one person will bet on a snail.

int placebet(int user_respons)

{
  using std::cout;
  using std::cin;

  int bet_amount;

  cout &lt;&lt; "Snail " &lt;&lt; user_respons &lt;&lt; " is a good choice!\n";
  cout &lt;&lt; "How much would you like to bet on your snail?\n"; 
  cin &gt;&gt; bet_amount; 
  return bet_amount;
}

//if just watching the race
void race(void) 
{
  race(0, 0); 
}

//if they are betting money. 
int race(int money, int user_respons)
{
  using std::cout; 
  using std::cin; 

  //Stores random number
  int winner = rand() % 3 + 1; 

  cout &lt;&lt; "And the snails are off!\n"; 
  cout &lt;&lt; "Look at them go! \n"; 
  cout &lt;&lt; "The winner snail is " &lt;&lt; winner &lt;&lt; "\n"; 

  if(winner == user_respons)
  {
    cout &lt;&lt; "You win!\n";

    return money * 2; 
  }
  else 
  {
  cout &lt;&lt; "You lost.\n"; 

  return money / 2;
  }


  //Handles the program start random
  void init(void) 
  {
    using std::srand; 
    using std::time; 

    srand(time(0)); 
  }
</code></pre>
