We're at the end in the sections we should be doing some practice now in concert with problem one.
So write a program that takes a radius is input and calculates the diameter circumference in the area
of the given circle using functions.
So we'll be needing some functions and double for our type in each room have functions for the diameter
and for
radius
in the center comes from us
and area.
So it's just right.
The main function code for is say radius and see out
please tear your radius circle
C in the radius and see each
diameter
circle is.
Call the function
at and.
Or the rest of it.
And it's super cool.
It's.
It's finally the area
that one thing will need is the constant
in say double and PI B pt. 2.
Calculate all these things.
Point 1 4 1 9 is good enough.
So nos.
I'm creating this outside of the main function.
This makes it so that's it's global to the entire program.
And this is a constant not a variable.
So this is OK to do so if this is a variable this would be bad but since it's a constant it's not ever
going to change.
It's not a problem.
So now it's right the functions
this so if you remember the diameter is really just two times that radius Sancy two point o time radius.
And that's all there is for that on the circumference is two times the radius times Pi or so you get
the circumference of the circle the outer edge of the circle.
And finally the area is
I
times the radius square right.
That's it.
So it's run this
time.
Five say and diameter is 10 conferences three point four something.
And the area is seventy eight point five three nights.
Is just going over some simple return value and parameters and that's it so the next problem is write
a function that gets an integer from the user and do all the appropriate error checking.
So we've kind of already seen this before and let's just comment stuff.
OK.
So let's write a function or to name it.
So it's going to turn an integer and C gets integer
user and
that's going to be the name of it.
So we saw this before in the last section with looping.
So it's really asked us to do is take all that and then put it into a function.
So it's going to return an integer and there's going to be no parameters.
So I told you we're going to be returning to input again and again and we're still going to see some
more input examples in the next two maybe three sections.
So let's just write that definition of get integer
integer and user call that right.
So if you remember it's just have a Boolean for if we failed.
So if the user typed in something incorrectly we're going to set that boolean to true
integer for the number.
Remember we're in use the do while loop you while while there's a failure rate.
So we want to keep doing.
Want to keep prompting the user as long as there is a failure and we set the failure to be false.
At the start because at the start of the loop there is no failure rate.
He's chair integer
mirror.
If so if you remember if there there's a failure we say see and fail on it.
Now evaluate to true if we are in the failure state and we have to clear that state and then ignore
any of the harmful
effects we probably need another fiery here counts.
Nor shoppers
sex it by the way.
256 is just kind of arbitrary is really Nannar probably put it to maybe even higher.
If I could and it ignores that many number of characters up until a new line in or is going to output
as input air
in or is it just please try it.
And if the set the failure flag to be true.
There was a failure in this case then we have to do is return the integer number and here in the main
reason to say
the number number is called to get ger for my user
bat and we're going to print out the number and number you got us
number
so sag and Fred.
So he says please try again.
So it's wrong.
Some random garbage that's wrong.
And 10 you got the number 10.
OK.
So if you're wondering why I keep harping on this example of the input it's because I really don't need
input in the next section which is finally where are you going to make the game.
So and to do that we need to have proper input and you'll see exactly what I mean when we start our
game.
So I know it's been a bit of a slog to get through all these sections but next time we're going to finally
make a game.
And after after that we'll be making a lot more games more frequently.
So so joining me in the next section and watch actually star start actually doing our projects.