   Some problems im having
  three beginners issues:Computer guesses a max of 3 attemptsnumber of attempts is always -1wait signal not identified (if someone could tell me a decently short version of a wait signal it would be helpful)#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){int number, temp, guess, tries;guess = 0;tries = 0;cout << "welcome to the game" << endl << endl<< "enter a number between 1 and 10: ";cin >> number;cout << " I will guess it!";do{srand(time(0));guess = rand() % 10 + 1;cout << endl << guess;cin >> temp;if (guess > number){srand(time(0));guess = rand() % guess;tries++;cout << guess;cin >> temp;}if (guess < number){srand(time(0));tries++;temp = guess;guess = temp % rand() + 1;cout << guess;cin >> temp;}} while (number = !guess);if (number = guess){cout << endl << "I guessed it in " << tries << " attempts";cin >> temp;}return 0;}
  srand(time(0));Seeding should only be done once. Please read up on the concept of random number generators if you don't understand what seeding is.number = !guessThis does not mean what you think it does. If you want to say "not equal", the operator is !=. What you wrote translates as: (logically) negate guess and assign that negated value to number.number = guess= is not the same as ==. The former means assignment. The latter compares for equality. What you wrote means assign guess to number.However your logic is flawed. Your logic follows something like this:1. Guess a number from 1 to 10.2. if your guess was too high, guess a number from 0 to guess -1 (guess = rand() % guess;)3. If your guess was too low, guess a number from 1 to guess % rand(). guess % rand() completely depends on guess. You are guaranteed that it will be a maximum of guess, but you have no idea what this is.4. If the number wasn't guessed, go back to step 1, where you guess any number randomly.Does this even sound correct to you?   ;  Be careful with your if and while statements. What does = do?Also, you don't need to reseed the random number generator (i.e. call srand) every time you want to call rand(). Just once at the start of the program is sufficient.   ;  i'm a little lost on the option of declaring a random max number, could you give me a refresher?1. Guess a number from 1 to 10.2. if your guess was too high, guess a number from 0 to guess -1 (guess = rand() % guess;)3. If your guess was too low, guess a number from guess to 104. If the number wasn't guessed, go back to step 1, where you guess any number randomly. (I dont understand how a number couldn't be guessed by the computer?)I know im a newb, but this is my first program in years, lol.   ;Quote:i'm a little lost on the option of declaring a random max number, could you give me a refresher?You need to figure it out mathematically. Think. rand() gets you some random number from 0 to some large number. You need to restrict how high this number can be. A simple way (it's not perfect) is to take the remainder. How do you get a random number starting from 5, or 6, instead of 0? Add 5, or whatever the lower bound is.Quote:I know im a newb, but this is my first program in years, lol.But you can still follow a proper problem solving approach. You don't have to be a programmer. The very approach you listed was flawed. You do figure things out on paper before coding, right?And that's the issue I'm raising. The code you wrote makes no sense on paper. Maybe it takes you a really, really long time to figure out how to solve the problem on paper. But you need to do this before you code.So here's what you should do. Figure out the logic in plain English on paper. Test the logic. Walk through your logic and see if it holds up. Instead of showing us code, present us your pseudocode. Until you get the algorithm write, don't work on the code.   ;  "You do figure things out on paper before coding, right?"NONSENSE SIR! just start copying and pasting things from whatever window you have open to your code, then sort out the compiler errors, then fix any runtime errors.<spoiler>Don't actually do this</spoiler>   ;  My pseudo-codeDeclare / initialize value'sRequest and store numberCompute guess patternEstablish initial guessCompute greater than / less than initial guessAdjust computations for new barriers (loop)Calculate new guessCompute greater than / less thanAdjust computations for new barriersSuccess;  Two problems. Your pseudocode involves meaningless statements. Second, does it even work?What does "establish initial guess" mean? Does it mean guessing 0? Guessing 1? Guessing 2? Guessing 3? Guessing 4? Guessing anything? Guessing with a gaussian distribution? With a poisson distribution? Guessing 42?What does "Compute greater than / less than initial guess" mean? What does your calculation involve? Where are you storing this result?What does adjust computations for new barriers mean?Apparently, you make two guesses in your pseudocode. In other words, you can guess a number in two guesses. Amazing. Is this true? Why don't you use your algorithm to guess a number. I am thinking of a number from 1 to 1000. You've got two guesses.You are not writing code, but you need to specific. "Declare / initialize value's" Declare what? Initialize to what? 2? 4? 8? Declare three variables? Declare 4 variables? Declare 5 variables.Tou're not specifying anything. Play this game on paper. Pretend you are the computer. Play the guess the number game. Look at what you are doing.   ;  Arcand, your original code seems to imply you might be misunderstanding what the modulo operator % is doing.% returns the mathematical remainder of the argument on the left divided by the argument on the right.It is not a symbol associated with rand() that makes it spit out a number above the number on the left or below the number on the right.  Think of % as you would a "+", "-", "*", or "/" sign.  It is frequently found after rand()because it is a convenient way to obtain a number between 0 and the number on the right.5 % 5 = 06 % 5 = 17 % 5 = 28 % 5 = 39 % 5 = 410 % 5 = 0etc.ETA:  rand() itself always returns a "random" number from 0 to a constant RAND_MAX, which is already defined and is at least 32,767 IIRC.  rand() itself does not see the % symbol and the number to the right of it.  Think of it as just a number.  If rand() returned 4567 for example, rand() % 5 is the same as 4567 % 5.If you want a random integer within a range, the argument to the right of % should be the total number of integers in that range.  Then you can add the low end of the range to readjust it, just as you do when the low end is 1.For example, if you wanted the computer to guess 1,2,3,4, or 5, you would use rand() % 5 to obtain a number 0,1,2,3, or 4, then add 1.If you wanted the computer to guess 4,5,6, or 7, there are four numbers in that range so you would want rand() % 4 to obtain a number 0,1,2, or 3, then add 4.As a general rule, rand() % ((High - Low) + 1) + Lowwill get you a random number between High and Low, including both HIgh and Low.  Since in many examples, Low = 1, you wind up withrand() % High + 1Also, as has been said, only seed your random number generator once.  Sticking it at the beginning of the main body of your program is fine.[Edited by - Crowseye on June 5, 2010 6:52:27 PM];  Thank you I think I understand, if I don't, you'll know it soon enough :)   