@senhor - you shouldn't use infinite loop(especially, when it's so easy to avoid).
@AKP - first thing - don't use global variables when you don't need to. Generally try to avoid them, they're bad programming practice (
http://stackoverflow.com/questions/484635/are-global-variables-bad ).
Well, try to run your program in your mind, like you were computer. If you don't find errors(don't know what's wrong), read my post further.
First of all, two = 90. Therefore, if you use number % two, you won't achieve what you want to(number between 1 and 100). To get number between 1 and 100, you should try:
number = (rand() % 100) + 1;
Why? Mod returns reminder. Reminder from 100 can be anything from 0 to 99. If you add 1 to the result, you will have a range of 1 to 100. If you don't understand it, try putting here different numbers, and using modulo for different numbers. Eventually, you may google it.
Secondly, you randomize "one" twice, here:
1 2 3
|
one = rand() % two;
do {
one = rand() % two;
| |
You could just one of these.
By the way, your code isn't readable - please try to improve your programming style. "one, two" isn't telling us anything. You could change these to "Guess" and "limit", or just leave "guess" and always mod % 100.
And well, I don't really know how can I help you. I don't know how do you want your program to work. You could either try randomizing one every loop iteration(but then it may take long time, and you don't need to change anything except for tries), or you may want to go - as your program suggests - higher or lower, according to help from user. If so, then you should change one, and stop randomizing it every loop iteration, but rather randomize it once and then increase or decrease its value.
Also, in your
1 2 3
|
if(user_input == "yes") {
++tries;
break;
| |
Simpy do this:
1 2 3 4
|
if(user_input == "yes") {
++tries;
guessed = false;
}
| |
And fast fixes:
- Change while loop condition, you are using operator= instead of operator==
- Define tries. It isn't automatically set to 0 - you should do it.
That's all what I can see now. I hope it helped ;)