all right in this tutorial we're finally
going to learn about the don'tdon't
return values it's going to be freaking
epic so basically a function can do one
of two things it can just go ahead and
plain and simple run whatever lines of
code are inside it like print something
out on the screen tomato tomato
or what it can do is it can calculate on
some equation a bunch of numbers and
give you back the answer so up to now we
just been putting void which pretty much
means just run whatever lines of code
are inside the function but right now
what I'm going to do is I'm going to
make a function that's going to run some
equation and return an integer and we'll
say that this function is 4 I don't like
a company that wants to calculate the
bonus or the extra money that its
employees get at the end of each year
maybe a Christmas bonus who knows who
cares
so of course whenever it does this we're
going to want an answer back so we can
use it later on in our program I don't
know maybe you like that right on their
paychecks or store in a database or
something
anyways so I'm just going to name this
calculate bonus and this is pretty much
the same as before except instead of
void right here the first thing you
write is what type of data are you
looking to get back well we're looking
for int we'll say that we won't worry
about the cents we're just worried about
the dollar amount so int which would be
the dollars and of course their bonus is
going to be dependent on um we'll say
years worked so the longer you work
there the more or the higher bonus you
want or you're going to get however you
want to say it so now we have to make
some stupid formula so say the bonus or
the extra money they get is equal to how
many years they work there times I don't
know it's a good amount 250 dollars I'm
a generous boss so if you work there for
two years you get five hundred tomato
tomahto actually let's add one more
condition so we'll say if
you work there for over ten years and it
will give you something out so bonus um
plus equal to one thousand
all right so sounds like a pretty sweet
company to work for
so basically going to take the year's
work for each year worked you get two
hundred fifty dollars and aside from
that if you work there for over ten
years you get an extra thousand bucks
pretty freakin sweet so up to now what
we did is you pretty much just hit
return and return mint okay I'm done
with this function but whenever you
return anything other than void you
actually can't just write return
semicolon
you need to write what are you returning
well in this case we are returning or
giving them the answer which is the
bonus so that's the main goal of this
function right here to calculate the
workers bonus so I'm going to return
that and now this function is complete
we just need to do our housekeeping
stuff so again the first thing we need
to do is prototype the function so copy
this paste it up here and now whenever
computer runs across it it won't get
confused and knows that this is a
function that we created now inside main
let's just go ahead and call this
function so what I want to do is I want
to calculate the bonus for two employees
so of course whenever I calculate the
bonus I'm going to store inside a
variable so the first one will be the
bonus for me which is Bucky's bonus and
again I'm going to set this equal to
actually I can just calculate bonus and
then the number of years that I worked
there so I'll say 14 years so what this
is going to do is going to say okay go
ahead and run this function right now
which is calculate bonus entry year's
work is 14 so 14 times 250 plus an extra
thousand and return that entire value as
this so right now
whatever that value is it's pretty much
in place of this function right here so
that value gets stored in Bucky bonus so
now we can use it anytime we want in our
function as many times is it or any time
we want in the rest of our program so
let me do that right now so now Bucky
bonus is equal to some dollar amount so
let me find out how much money I made
so Bucky gets and I'll put dollar sign
and percent D and do I want to add
anything else that's very good
so Bucky bonus actually let me code one
more real quick say that there's someone
else I'll put something less than ten um
so say there was kind of a new chick
that started working there called Emma
and she's only been working there for I
don't know three years easy right click
alright so print out Emma right there
and everything looks good so now let me
go ahead and run this and check it out
so not bad so my bonus was $4,500 in
Emma only got seven hundred and fifty
dollars alright not bad I mean it sounds
fair to me
so one more time this is what happened
whenever you use return values what it
does is whenever you call the function
it pretty much calculates the function
and whatever it returns it sticks in
place of right here so right now all
this code that I highlighted was pretty
much equal to four forty five hundred
all this code is pretty much equal to
750 so now you can just store it inside
a variable or you can even do something
like this since this is equal to 750
check this out
and let me put this for Bucky's bonus
and we can even delete these lines
altogether if we want so now we're going
to run this check it out the same
thing so pretty much the conclusion of
this tutorial is whenever your return of
value it pretty much returned or trades
that function call for that value and
you can use it just like you would on
the variable itself so hopefully you
guys understand again it's not this or
it's not that complex once you like
practice with three functions you're
going to get the hang of it you're going
to be a pro but for now thank you guys
for watching and the next video guys
it's the series finale so make sure to
stick around I'll see you then