0

its a random number generator

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip.h>
using namespace std;
int main ()
{
const int MAX_RANGE = 100;    
int value;
int random = rand( );
int num = ((random % 100) + 1);
int quit;

do
{
srand (time (NULL));
value = rand() % MAX_RANGE + 1;

cout << value<<endl;
cout << "Enter 0 to end program: ";

cout << "Guess a number between 1 and 100: ";
cin >> value;

if (value > num)
{
cout << "The number is lower. Try Again\n";
}
if (value < num)
{
cout << "The number is higher. Try Again\n";
}
else if (value == num)
{
cout << "You've guessed correctly\n";
system ("pause");
cin >> quit;
}
while (quit != 0);
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by WaltP
0

Don't know. What it do wrong? If you want help you really need to explain. Read the Member Rules.

The thing I noticed is your srand() is in the wrong place. Put it at the beginning of the program so it's called only once.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.