Stew's practice now you see problems is create a function that takes two vectors and returns that dot
product.
The two vectors two vectors must be the same size so it's no such thing as a vector space but we can
use an array.
So let's say we had an array of say
1 in 3
4 7
scene Victor 2 it's also 3.
To say these are two three dimensional vectors K in let's write a function or actually you saw double
doubles
and rate a function called the product.
And this takes in two arrays and they're going be constant because we're only going to read from a vector.
We're not going to actually change that that way.
Of all cause factor one or two and the lengths of the vector
scope that it does here implement.
So what is the dot product of two vectors as well as just each of their components multiplied together
and then added.
So it would be one times two plus four times five plus seven times eight.
So one product is 0 and then Absolute through the array.
This link
boss knows we need the link here of course because otherwise we don't know how many how many elements
each vector has.
It was a product plus equals vector.
One of times the keys at the end there.
It's wrong vector to
return the product.
So use this say that dot product
or let's see how it's
dot product.
Jer. 1.
2 is
her one vector to in the link is 3 right.
It's from this see.
So the dot product of vector one vector 2 is 78.
It seems to make sense to you.
Plus when he was
sometimes h
sometimes eight
us to was 20 year.
It's not OK
so that's the first one.
Suze says it's a make a function call get character that will take in a C string prompt and the string
and return a character from standard in and from the user.
So this is going to build on our input examples that we've been kind of going through throughout the
course if the user types something incorrectly or doesn't match our inputs the function should recover
from failure gracefully and output the error C string and promp easier to try again.
Ok so its main function returns a character get character
in.
This will be the ROM.
It's char.
This and the error string
here
that's.
So most of this should be very familiar.
So we need the input and can reuse that failure.
And we use do while loop as we want to be able to do more than one time failure.
Right.
And we want to do it more than one time because they could input something correctly.
So failure to all false
in will output the prompt Changs.
So this is from the is one of the arguments which is output the prompt.
You don't know where it is in its input to get the input and then just like before we check to see if
fail the you know that's
a case in this one.
And for this we have to clear the flag.
And ignore that we actually need constants.
And in fact I put it up here.
Inch or Shahr is more 256.
Again that's very arbitrary.
Nor
for sure is up until the newline right.
It's all old stuff and we should output the error rate here.
Either will input the air or the programmer will set the air for this function right.
And failure is true in this case.
Otherwise.
So what we want to do is to actually ignore any characters after this or this is the case where it worked.
Or there was no air
and I'm going to do something a little bit new and say If so what I want to say is like if it's a character
write it not like an integer or say or something like this double.
So if it's character
hey put it it's these
I don't know how to do that yet but I'll show you in a second.
I want to do have it in lower case inputs.
So we need the CC type you remember colludes type so that actually has a function that will lower case
the inputs to lower this input.
This is exactly what we did before.
So we shouldn't be any difference and we're going to output the error if it wasn't a character so it
wasn't a character and go here and we're going to output the air again at and say that that was a failure.
And you can actually check to see if it's character using CC type.
In fact it's called is alpha
and then don't actually say whether or not it was a character
or its return.
This and so try is once you read this
and try to get a character so will say Shaar input.
Goulds to get this character and the whole point of this was to pass in the prompt itself.
So say please enter character that is.
And also the air string.
So
input error.
Please try again.
And then we'll just output the character itself.
There Jerry
put these
this
are on that piece and put it character into one.
So see how this was an input error because that's not an alphanumeric character or alpha character.
It's not part of the alphabet.
Is is alphabet.
Right.
So if you see Affe characters Frank So that's working pretty well.
So there's actually another part this says create a new function that is called character that will
also take in valid inputs that the user can type in and how many there are.
So the functions should only allow those inputs by the user and give an error if the user didn't input
it correctly.
So to do this we're actually going to use an array so and also take advantage of
functions that have the same name.
It's function overloading.
So we're going to still have the same thing so as to be prompt this and conc our star error but it's
also going to have extra things called Call it counts Chaar valid input and that's going to be an array.
And so we're going to actually input all the valid characters that you're allowed to type in here.
And let's say it's valid and what it's like.
So we need to have the length of the array right.
This isn't a C string.
These are actually just caret is just a character array
that and for the most part it's going to be quite similar to this one above.
So we're going to copy all of this
and rewrite it.
And the difference will be here.
So after this we're going to lowercase it and then we're going to check all of our valid inputs here.
So a valid input.
Link loss and we're going to see if the input that we got is one of those allowable inputs like this.
And if it is we're just going to return the input and that's it.
So we are going to try this again but we're going to have some character so let's say we had.
And you'll see in a really quick second why why we're writing this function at all.
So character say valid inputs are let's say yes and no
care if you see where we're going with this.
These enter.
So let's say for the prompt it should be.
For example would you like to play.
Why is slash and tear.
And then here we're going to say valid inputs and there's only two of them.
Right.
In order on this
spelt was incorrectly
put this
time.
OK.
Would you like to play again.
So if I remember back before we could like say q and you'd still say no.
Right.
So we don't want this action.
Because otherwise it would have it would have done this.
But then kind of.
So the reason why that didn't work is because it was an actual alphanumeric character and it did this
but it didn't.
It didn't return true here.
Right.
But it didn't go to this case that we wanted it to.
So we actually remove the else case so and we can do that because we're actually just returning right
here instead.
So let's try this again.
So it's a Q That's an input error.
You mean put there.
No your character was and you're doing this again and.
Yes.
Right.
This is working this way.
So you see why we're writing this function.
This is going to be a pretty important function for not only the next project we're going to do the
one after that as well.
So I'll see you in the next section.