i'm not used with c++ (only programmed with c++ a pair of times) but I think the issue is on rand declaration.
Try using rand() % 3 + 1;
If this don't work regard to time(0), it may take a "NOW" value to properly randomize (usually programming languages take miliseconds to randomize).
PD: I may be wrong on what i said of time, comment on there if those two solutions doens't serve you.
There is an example of rand from 1 to 10 working:
/* rand example: guess the number */
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
int main ()
{
int iSecret, iGuess;
/* initialize random seed: */
srand (time(NULL));
/* generate secret number between 1 and 10: */
iSecret = rand() % 10 + 1;
do {
printf ("Guess the number (1 to 10): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);
puts ("Congratulations!");
return 0;
}
Cheers!