#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#define MAX_RANGE 1000
main ()
{
long value, guess;
int tries = 0;
srand ( time (NULL) ); // Initialize random generator
value = rand()%MAX_RANGE+1; // Get random between 1 and MAX_RANGE
cout << "A random number has been selected between 1 and 1000." << endl;
cout << "Try to guess the value.";
cin >> guess;
tries ++;
while (value != guess)
{
if (guess > value)
{
cout << "The value is lower than " << guess << " Try again." << endl;
}
else if (guess < value)
{
cout << "The value is higher than " << guess << " Try again." << endl;
}
else
{
cout << "You guessed the value!!" << endl;
cout << "It took you " << tries << " tries to guess the correct value." << endl;
}
cout << "Guess another value." << endl;
cin >> guess;
tries ++;
}
return 0;
}
So I've written this code here to guess higher and lower numbers. It compiles and runs properly, but I have a question regarding compiling it. Dev C++ comes with a GUI compile button, so the command prompt is unnecessary. Unfortunately, when I use this button, after the program is finished, the command prompt automatically closes. So I was curious how to compile using the command prompt to avoid this problem. Additionally, I know that I need to specify the directory where my code is located. How can I changed the directory the computer is currently looking at?
By the way, how come code tags aren't working properly... Shoulden't this be numbered now...