1. after just a quick look: Originally Posted by cgod
I changed your code so it works i hope this gives you a general idea of how to generate a "random" number next time Code:
```#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(int argc, char *argv[])
{
srand ( (unsigned int) time (0));
int x = rand()%5;
int guess;

do {
cout << "im thinking of a number between 1 and 10\n";

cin >> guess;

if (guess == x) {
cout << "you are correct\n";
}
else if (guess < x) {
cout << "guess a higher number\n";
}
else if (guess > x) {
cout << "your not supposed to guess this high\n";
}
else {
cout << "guess a lower number\n";
}
}while (guess != x);

system("pause");
return 0;
}```
1. if it's between 1 and 10, why are you using mod 5?
2. you already have larger, smaller, and exactly covered, what else are you trying to do here?
3. don't use system("pause"). ever. 2. Yeah ok but i just changed cerin's code so it would work he can do all the minor adjustments.I found this code from awhile ago maybe it will be usefull to cerin.
Code:
```#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
srand((unsigned)time(0));  // random number seed
int numberToGuess = rand()%5; // generate random number between 1-5
bool win = false;
int guessNumber = 0;

for (int numberGuesses = 0; numberGuesses < 5; numberGuesses++)
{
cout << "The computer has generate a random number try and guess it " <<endl;
cout << "Guess : ";
cin >> guessNumber;

if (guessNumber == numberToGuess)
{
cout << "Correct "<<endl;
win = true;
break;
}
else if (guessNumber > numberToGuess)
{
cout << "To high try a lower number"<<endl;
win = false;
}
else if (guessNumber < numberToGuess)
{
cout << "To low try a higher number "<<endl;
win = false;
}
}

if (!win)
{
cout << "You have lost the game try again "<<endl;
}

cin.get();
return 0;
}``` 3. Originally Posted by cgod
Code:
`int numberToGuess = rand()%5; // generate random number between 1-5`
try again... 4. Originally Posted by major_small
try again...
Code:
`int numberToGuess = 2; // generate random number between 1-5`  5. Trust Prelude to come up with something like that.. Hm, I'm going to try doing Impossible Thing to Do #1. 6. Originally Posted by chrismax2
I cant belive some of you comment, that people dont post there code correctly, i mean at the end of the day, it dont matter. Trust me it does matter. Its easier to read, and when your using the [ PHP ]. It color codes it so its easier to tell whats, a comment, whats a function, ect.  7. Code:
``` srand ( (unsigned int) time (0));
int x = rand() / (RAND_MAX / 10 + 1 );
(int)( (double) rand() / (RAND_MAX +1) * 10);
int guess;```
It still doesn't change everytime I run it 8. Might I make a recommendation????

Go to a C/C++ textbook. Open it to page 1 and begin reading from there. The moment you try to gloss or skim over anything...STOP and re-read it again. You've obviously not grasped a single programming concept. Not even the most basic of principles or logic. And now you're turning a very very very simple statement into the most convoluted mess I've seen in a while. How on earth did you migrate from x = rand() % 10, to that indecipherable muck srand ( (unsigned int) time (0)); int x = rand() / (RAND_MAX / 10 + 1 ); (int)( (double) rand() / (RAND_MAX +1) * 10); int guess;?

Good god man!

Really, honestly I'm not tryin to be rude, but you've got to start from the beginning otherwise your confusion will just get worse. I've seen you struggling through other pieces of code in other threads, and I really mean it when I say I would rather see you progress and succeed instead of struggling and losing interest. 9. UMMMMMM...... really the first things I did were ACTUALLY READ some basic tutorials from http://www.geocities.com/tutorialperson/ (I'm on my mac laptop it won't let me make it a link) and then I READ the tutorials from this site.
I'm working on getting a book. The code I had was posted and in the FAQ. 10. I really hope this helps...

Code:
```#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
//First, we seed the random number generator based on time with srand
//so that we don't get the same random numbers every time
srand( time(NULL) );

//Now we assign a variable to a random number
int foo = rand();

//Now we assign a variable to a random number between 1-10
int bar = (rand() % 10) + 1;

//Now we print 10 different random numbers between 1- 100
for( int x = 0; x < 10; x++ )
{
bar = (rand() % 100) + 1;
cout <<bar <<endl;
}

cout <<'\n' <<endl;

//Now, we have them guess a number between 1 - 10
int number = (rand() % 10) + 1;
int guess = 0;

while( guess != number )
{
cout <<"Guess my number(between 1 - 10): ";
cin >>guess;

//Is guess between 1-10?
if( guess < 1 || guess > 10 )
cout <<"I said between 1-10, try again dude." <<endl;
//Is it greater than our number?
else if( guess > number )
cout <<"Too high, guess lower." <<endl;
//Is it lower than our number?

else if( guess < number )
cout <<"Too low, guess higher." <<endl;
}

//Since we've left the loop, we know they guessed correctly
//...or there was a freak of nature, but we will ignore that case
cout <<"You got it! Thanks for playing." <<endl;

}```
This code is extremely straightforward, and if you still have questions after reading the FAQ, this post, and all the previous posts concerning the generation of random numbers and seeding the random generator, maybe programming isn't your bag, dude. 11. Alright I got it now thanks for all the help. One of my teachers is going to look if she can find a mentor for me at the college. Popular pages Recent additions 