So how can we kind of remedy this situation that we have right here?
Well, something that we can do is, you know, if the scene fails.
So this is just like a very kind of hard coded example, but, you know, we know that it failed here
on this.
You know, this integer when we entered a B, so I just kind of want to show you what's going on with
this keyboard buffer and how we can actually change it to still read in this 10.
And this isn't going to be like a super programmatic way, but it's meant to just kind of show you what's
going on with the keyboard keyboard buffer.
So we have this scene to fail, right?
If it fails, I can actually do something called in dot clear.
The C unclear is actually going to.
Clear.
The failed bid, so this thing that happens is that there's basically a failure in the seeAnd input
which happens here on this character, right, because we expected an integer.
Yet it was a character, so it's kind of messed up everything at that point.
So what we have to do?
Is when it fails, we need to fix that failure, so we need to clear that like it was called kind of.
You can think of it like a flag.
Quite often people refer to these things as flags, but there's kind of some flag that gets set that
says, Oops, stuff failed.
Everything's messed up now.
What you can do is see CNN since you're using this object still, as you can clear that failure out
by using the dot clear.
So this says OK, we notice we failed, go ahead and clear that fail so we can continue doing stuff.
So then what we can do is have.
A scene in Dot Ignore is this other thing that basically says, OK, like we cleared the failure, but
what we're going to do is we're going to ignore this like.
However, many characters of failed input came in in this case, we just have this.
One character right here, right, which is a B when we expected it in, and so if I go see and ignore
and I put a one in there.
It's going to ignore this B and then kind of keep going.
So let's go ahead and see what happens when we just leave it like this.
So I'm going to go ahead and save.
I want to run this a 2.7, b 10, so you notice that it still is kind of messed up here.
So let's kind of see what happens if we were to read this in afterwards.
So I'm just going to put these three right here, and then I'm going to put this scene in two afterwards.
And so what I'm going to do is.
Let's see, I'll go ahead and.
Comment things out.
So I run this you notice it still has a garbage value.
And go ahead and I uncomment this.
And now what happens?
Pretty interesting, right?
So it had a zero.
Still, because this was like a failure, so it still failed.
But then what happened is we cleared the failure out so we could continue collecting input.
Then we said, OK, ignore that failed be.
And then afterwards, we went ahead and we tried to then take in this eye to so read in the eye, too,
which was the 10 that was remaining on the keyboard buffer, right?
This was actually Romanian on the keyboard before as a failed kind of thing.
So we kind of we ignored it.
But then we did want to read this and write.
So pretty interesting, so what we did was after we cleared this failure and then got rid and ignore
of this other thing, then it was successfully able to read in the ten here and we can just test this
again with another value too.
So if I was a, you know, eight point four or eighty nine point eighty eight point four, it can be
anything.
And then I just put it like, you know, age and then I put like 123.
So you notice it still does the reason the character, it reads in our float and then it failed on the
page.
But then it was able to clear that, and then it was able to ignore the age and then continue on with
this line where it successfully read this off of the existing keyboard buffer.
And if I was to put something after this, so I have i3 up here still, right?
So now it will actually be able to prompt me if I compile and run this again.
Let's go ahead and do the same things on the, say, a any eight point four age and one twenty three.
And so says oeufs and failed.
But now what happens is it's read this off the keyboard buffer and now it got to here.
And since we have satisfied, you know, all of the stuff that we've asked for already with this input,
then it goes ahead and pauses and starts for us to enter something else.
Because you noticed that we had we basically asked for four things.
So here's one two three.
Then you noticed this one failed, right?
But we cleared it.
We ignored that character.
And then we read this other thing off the keyboard.
So we asked for four things.
One, two, three four.
And we gave it four things one two, three four.
So since we gave it the same amount of stuff and asked for now, when it asks us for a new thing, it
stores ways for us to enter it, which I can just put, you know, whatever.
And then it goes ahead and it finishes.
Of course, we're not printing out this i3 anymore.
You know, I could uncomment this.
I could save this compile.
And again, to a a let's just do seventy eight point four eight point twenty three, then I could do
this forty five and you notice that now that forty five gets printed out, actually.
So it went ahead and did this, dealt with the air.
Read this Off the keyboard buffer, it printed all this stuff out.
Then it was able to read in our forty five and print this out.
So pretty cool this year and ignore it, can have some more functionality, you can put some other things
that tell it to go up to the end of the line and stuff.
We're going to get a little more into that stuff later.
So we'll look into kind of making more complex programs with not only reading stuff in from the console,
but we'll read stuff in from files.
When we do that, we're going to kind of expand on this knowledge here, but I wanted to give you enough
of an introduction to it where you felt like you knew it pretty well and you at least understood what
was happening.
When people are entering things here on the console and it's being read into the program.
So just like I said, if you can't remember all of these, like fail clear and ignore just, you know,
if you just remember what seeAnd fail does, you know that's enough of a of a success.
But the main thing to take away from this lecture and the previous lecture is that you kind of are able
to understand what happens when you put these in a different, a different order.
So some interesting things can happen.
Actually, I might do another quick example.
So because I want to kind of want to show you what happens when you read in a CHA- like, let's say,
after a float or something, we'll just switch these around out for an integer and then I'll put a cha.
And then I'll put a float.
Yeah, and then.
We're actually learning to float here, so integer and a float and then a cha.
So I'm going to kind of show you just some different things, just so we can drill it in, it's another
example before we finish up here.
So.
Now I have it.
I saved it and compiled it, and it has and the integer first and then a float and then a char.
So.
If we can do enter some input in an interesting way, if I put a two point seven here.
And then I put let's say I did that instead of an integer, I actually accidentally entered two point
seven.
And then I did like a three point five or something like that.
And then I did a B.
Let's let's see what happens with this.
So I'm going to run this.
So.
What happens is I'm actually, yeah, actually this is out of order, so let me let me put this in a
different order now, so I'm actually going to say and.
And then float, I got to make sure to put the spaces over for an extra space, actually.
And I might want to actually put my integer.
So then I'll put float and I'll put the.
And then I will put Cha.
And then I'll put the see.
So let's just do.
Let's just do this.
I'm going to save it.
Ignore that example.
I'm going to compile this and run this.
So let's do it.
Let's do this.
We have this 2.7, right?
So I accidentally enter a float instead of an integer and then now I enter a float as well, and then
I enter a b.
So what we see here is that.
We get a two for the integer, because what happened is that.
It saw this, too, and even though there was a point seven since it had this to was a valid integer,
the point wasn't a valid part of the integer.
Then it basically stopped and it read this to in for the end, which is totally valid.
Then what happened is the float didn't end up being, you know, two point seven or three point five.
It actually saw the next thing on the keyboard buffer, which was the point seven.
So it turned that into a float and it put a zero instead of just zero point seven intact on this zero
four zero point seven.
Then what happened was we had a char and we expected it to be the B, but it wasn't.
In fact, I remember a number can be a valid char.
Remember, in the last lecture, we had it labeled the rectangle as the number eight because numbers
are valid chars.
You know, you might like want that as a piece like an actual character.
If you think you like the ASCII table, you know numbers can be valid characters as well.
It's not seen as a no, it's just seen as a character, because maybe it was like a name of something,
you know, like building eight or something, not just like.
A number, so it reads that it is a cha.
And then afterwards, you know it.
Basically kind of leaves the rest of this on the keyboard buffer.
The next thing we had was this I, too, which is supposed to be an integer.
So and then we have this last end, so we're not really printing out the eye to actually actually comment
to out.
But, you know, the integer basically tried to read in whatever came after this char.
You know, that was read in after the check for the sea and fail, so it failed, but it didn't really
know that it failed.
So I'm going to go ahead and just comment that out.
So it's not extra confusing.
But then this last one was garbage, right?
Because it wasn't really able to properly read into it because it failed.
And also, you know, we had a car here anyways afterwards.
So but it failed on this when it was trying to read that into it to.
So, you know, I can comment this out, and now we just have this.
Go ahead and.
Get rid of this.
But we can put something else, let's see, instead of seeing to a three, I'll put a.
Let's see into
let's make like some other Char, so I can say like Char B or something like that, and I go ahead and
I read into this char b, go ahead and delete this and then I'll actually see out a second char.
And I will put this be right.
I'm also going to put it in line at the end of this month.
So now let's let's kind of go through the same example.
I'm just doing, you know, quite a few examples just so we can really like understand what's going
on.
So I'm going to say that I'm going to compile it and write it again.
So let me try and enter the same stuff.
We'll do this two point seven three point five So we're just pretending like, Oh, let's I forgot it's
in and I'm just going to enter two point seven and then I'll continue on unless if I'm reading my float
in and then I'll put a B.
Right here.
So let's see what happens, so what it does is it still does the same thing, right?
We haven't changed the kind of the initial part.
It reads in the integer two since there's a point after it's like, Oh, I'm just going to read it in
this integer two because it's supposed to mean and then the float ended up being this 0.7.
That was the next thing on the keyboard buffer.
And then this was the next thing that was in the keyword buffer was this like valid char, which is
three.
The next thing on the keyboard buffer, it was all this stuff, but the exact next thing was this dot.
So what happened was this dot was seen as a valid car and it was read into the B.
So the period was read into the B.
And so that's why it printed that period out right here.
The rest of the stuff, you know, it actually failed.
So it it didn't it failed kind of after or actually we took it in and the rest is on the keyboard buffer,
so it actually didn't fail.
If we tried to read in further stuff, we actually could.
So I could see in at this point into i3.
And then it should have this five here, so let's go ahead and check that out, right?
Because we're just kind of keeping track of what we've done.
Well, reading in thus far.
So Chas was valid up to here and then this was left over on the keyboard buffer.
So I'm actually going to show you that this won't stall.
So I'm going to copy that.
And what I'm going to do is put put it after this.
So we're going to print this stuff out and then ask it afterwards, and I'll show you that it doesn't
stall.
What it's going to do is actually just read this integer.
Read this as an integer off the keyboard buffer, and it's not going to like pause and wait for us to
enter anything.
So I'll do that same thing, so two point seven, three point five B.
Oh, well, we didn't actually print it out, so let's go ahead and print it out, so we'll do last
last and it's going to be three and we'll do it in line.
OK, so I say that I come highlights.
I run it.
Let's do this again.
2.5, three point five B OK, so and there we go.
We see the five now.
So same thing.
The integer was seems the to the float was seen as eight point five.
I didn't put 0.7 seven.
I guess it was supposed to be 0.7.
I forgot.
So there's point five and then that this was the next thing that it read in was a char, then the next
char that it read in for the second char was this dot, and then this last integer that was I three
will actually read this in and printed that out.
And we have this left over on the keyboard buffer.
OK, so hopefully that was like enough examples for you to understand this.
I kind of was about to finish and I wanted to do this last couple of years.
So thinking that maybe this example wasn't a specific one, we've gone over, so maybe it would help
you understand it even better.
So.
Yeah, just be aware of what's being read into what data type.
Right?
And this stuff, if you if you can remember it, you know that would be good.
We can always use it.
What we're going to be doing is we're going to notice that we're going to need to use it in the near
future.
When we look at a another type of getting input with something called get line, which gets an entire
line all at once rather than separate.
I know this was all in the same line, so it kind of gets a whole line all at once.
But the fact is is that we had to we had to use multiple of these operators, right?
And we were separately reading into different variables, whereas you can actually read an entire line
into like a string and stuff like that with scene and also this thing called get line.
So that's what we're going to learn in the near future.
And we're going to notice that if we're using a combination of seeing and get line, it's actually useful
to know these things, the ignore and the clear and stuff like that, and also really get to know to
be able to check for a fail as well because you can do other stuff when it fails like you.
You know, here we printed a message out like, oops and failed.
So it's just good to know to know this, and we will kind of elaborate on this in the future.
Like I was saying, so if this is too confusing, you know, don't worry too much.
We're going to be using them in some next lectures and stuff.
But main important thing that I want to you take away at this point is the fact that, you know, the
type of the variable that you're trying to read into really is very dependent on the type of input that's
being entered.
Like you notice here when we entered a float.
Notice what it did, it just only captured the two as an integer.
And then for the float, it just read the next thing and the keyword buffer when we might have thought
that it would have just looked at this whole thing and been like, Oh, an integer, it'll just say
two, maybe.
But then the flow will be this.
No, no, no.
This is what's next on the keyboard buffer, that's why it showed up here.
So understanding what the keyboard buffer is, understanding how the data types have to the data types
here and the variables have to do with the data types you're entering on the keyboard, the characters,
how those are interpreted as a data type.
So just keep that in mind, that's the main takeaway.
All right.
So I think that's enough.
So with that, I will see you in the next lecture when we kind of build upon this knowledge with some
other types of input stuff.