Yes, you need a loop and a counter to count how many time your loop executes. Exit when counter == 5 OR guess == random_number
Also be careful using = and ==
They are not the same and you have to use the right one for the right purpose.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Perhaps. But why not take the good advice from WaltP. That would be the easiest solution by far.
Niek
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Also, here is a piece of logical truth. Given
if (a < 10)
do this...
else if (a > 10)
do this...
else
when you reach here, isn't a == 10 automatically? No need to test it.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Then you need one if for each guess. They don't have to be nested, either. Each if simply tests the guess with the number and if they aren't the same, do what you need to do.
Within each if, get another number, test it for > and < and output the appropriate message. No need to even consider equal until all the ifs are finished.
As you can see, it helps to give us all the information so we don't waste your time giving you advice you can't use.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944