 So we're gonna play a time-honored tradition of a game called high low now how high low Works is it is effectively a little number guessing game. It's just our way to kind of work with a computer It's again time-honored tradition every programmer with with their salt learns this program so the first thing we have to do is we have to Make a number, you know a world we don't make the number again This is a now the computer starting to think it's starting to operate and one of the things that we're gonna have it do is We're gonna have it Take a random number from zero to a hundred and then we're gonna guess it so all right Well, that's as you can see step two we then ask the user we ask the user come here Do make a guess and then we do an assessment we do an evaluation Evaluation we see oh well if the user's guess is too high We tell them they're too hot, you know, it's the game of hot and cold warmer warmer hot hot hot hot. You got it Yay, that's what we're doing here. We're telling them if they're warmer or colder If it's too high we say it's too high if it's too low We say it's too low. We have to do an evaluation process and we continue continue We instead of continue we can think of this Right Take that up we loop We continuously run through it until we get it. So here's that code kind of just outlined This is a great way you can think about This is a great way you can Go ahead and work on your code before you even start to hammer it out before you even start to work on it Take what you're doing and you know just kind of put it in there As you can see this is going to give me a little bit of a step-by-step guide as to what I need to do So the first thing I needed to do was Generate a random number from zero to a hundred now I want to make this An integer a whole number because We're going to be dealing with you know, my user's not going to want I guess 3.1452987654321, you know They don't want to go decimals it makes the game a little little too hard. That's hard mode. You know, we're easy mode We're just learning this game. Uh, so you know, I'm going to name this uh number Simple variable name that's not out of this world that is called number And then again, we say math dot random times one And I'm going to do something here. Oh one now why 101 because Math dot random is going to generate some random number from 0.1 to 1.0 Not including 1.0. Remember that means if we think of this in percentage wise This will generate a 100, but it'll be 100.99999 something like that, but it will never ever hit 101 Now one of the things that I just mentioned was this is going to generate like 100.99999999 That's an issue again. We have to make sure that we're dealing with Integers not doubles and again if I try and compile this right off the bat if I just try to compile this I get lossy compression because I'm trying to make a double Into an integer. So if we run into obviously that problem So instead what we're going to do is we're going to do Casting now again, we are going to run into an issue This is going to cast this before this happens Well, this only generates numbers from 0 to 1 not including 1. So it's always going to turn it into a 0 So what I have to do is I have to take this And put it inside parentheses again remember order of operations kicks in This is going to get evaluated first that becomes some decimal point This becomes my whole number So now we get to look at this and one of the things I recommend is don't Start looping don't try and do the loop first Follow your instructions then put it inside of a loop My next instruction is ask the user for a guess ask the user for a guess System dot out dot print Enter a number I'm not looking at the while loop yet. I'm not trying to look at the while loop yet. I'm just saying give me a number and then string Dot guess or string guess equals input dot next line This is going to Just store that user's guess again. No loop has taken place yet. You know, I know I have to repeat We're not there yet We keep going. All right. Well now I can say If the user's guess is too high tell them and let them play again so if if Actually, I'm going to switch this from a string To an integer because we're dealing with an integer next int if Number Equal equal guess. That's why I changed it to an integer so I can do easy comparisons system dot out dot print line you are Correct else if remember we've got Three possible scenarios here if they got it right if they're too high or they're too low so Suddenly if number is less than guess my guess is too high too high well Again, I don't need to check to see if number is Uh greater than guess because I've already checked. Is it equal to My one scenario. Is it less than my second so by order of you know elimination There's only one possible state it can get in now Whether or not It's great. We can already just assume that so we can say Too low low Now again, I haven't made my loop yet one of the things I recommend before you start trying to loop this Because it's the first time you've seen a loop compile it make sure your errors are gone Enter a number. I don't know What the number is I don't I don't get that again. It's a game, you know, you don't get the answer So I'm just gonna say 50 Too high and the game's over now. That's the problem. Oh the game's over. That's no fun So now we go. All right. Well Let's let's play the game so Now what I'm going to do Is I'm going to take all of this stuff and I'm going to put it inside of a loop So the first thing I'm going to do here Is Right about here While Guess Uh does not equal Number Now some of you might already be screaming at something but I want to I want to just don't want to we'll get to it Now one thing we have to do As I kind of clean this up Is that I have to Change my guess I have my guess up here But now what about here? All right. I got to change my guess otherwise What's gonna happen so what I'm gonna do is I'm gonna actually Turn this into a just a declaration. I'm actually going to move this as well Into here But I'm going to get rid of this guess part I'm going to leave this up here now One thing I'm going to do is instead of doing input dot next int I'm going to say negative one Why negative one well if we think about what kind of numbers I'm generating Am I is my guess ever going to be a negative one? No, you know my number is never going to be negative one. I'm my user. Hopefully never times negative one So I'm already going to be wrong from the beginning. That's not a bad thing because as you can see right after this gets assessed Negative one does not equal my correct guess number boom Things happen So we save it up We compile it up Enter a number 50 To high all right 25 Too low. All right. So now I got like a 32 32 Too high. Ah, see damn Let's see somewhere between 25 and 32 cut that in half again. We're now dealing with about a 28 too low 30 too high 29 You are correct And as you can see boom boom Game over