My program causes my compiler to crash
I am coding a "guess the number" program and I hope someone can tell me what I have done wrong with my program. When I compile this program I do not get any errors or warning. It prints the intro to the screen correctly but when I put in my first guess it crashes the compiler. I am stuck and hope someone can point out my mistake.
Sorry for posting the whole program but since I am not sure where the error is happening in it felt I needed to show it all.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstdio>
#include <cstdlib>
#include <ctime>
int randomNumber();
void test(int yourGuess, int rnum);
void intro();
void main(void)
{
int i=0;
int rnum=0;
int yourGuess = 0;
int count = 0;
long ltime = time(NULL);
unsigned stime = (unsigned)(ltime/2);
intro();
cout << "OK, I am thinking of a number. Try to guess it.\n";
cin >> "%d", &yourGuess;
srand(stime);
for (i=0;1<1000;i++)
{
rnum=randomNumber();
test( yourGuess, rnum);
}
return;
}
void intro(void)
{
cout << "Welcome to the game of Guess It!\n";
cout << "I will choose a a number between 1 and 1000.\n";
cout << "You will try to guess that number. If you guess wrong.\n";
cout << "I will tell if you are to high or to low.\n";
cout << "You have 6 tries to get the number.\n";
}
int randomNumber()
{
int number =-99999;
number=((rand()+101) % 1000);
return number;
}
void test(int yourGuess, int rnum)
{
if (yourGuess < rnum)
cout << "Too Low.\n";
else if (yourGuess > rnum)
cout << "Too High.\n";
else if (yourGuess > rnum && yourGuess > 1000)
cout << "Illegal Guess! Your guess must be between 1 and 1000.\n";
else if (yourGuess < rnum && yourGuess < 1)
cout << "Illegal Guess! Your guess must be between 1 and 1000.\n";
else
cout << "You Guess it!\n";
}