WEBVTT

00:01.090 --> 00:09.200
We're at the end in the sections we should be doing some practice now in concert with problem one.

00:09.240 --> 00:18.500
So write a program that takes a radius is input and calculates the diameter circumference in the area

00:18.890 --> 00:22.900
of the given circle using functions.

00:22.910 --> 00:33.530
So we'll be needing some functions and double for our type in each room have functions for the diameter

00:35.770 --> 00:36.700
and for

00:39.040 --> 00:40.140
radius

00:43.860 --> 00:48.260
in the center comes from us

00:57.600 --> 00:59.540
and area.

01:07.670 --> 01:09.230
So it's just right.

01:09.230 --> 01:19.000
The main function code for is say radius and see out

01:21.250 --> 01:27.070
please tear your radius circle

01:31.580 --> 01:36.680
C in the radius and see each

01:41.720 --> 01:42.560
diameter

01:45.110 --> 01:49.900
circle is.

01:50.150 --> 01:51.410
Call the function

01:57.080 --> 01:59.840
at and.

02:00.080 --> 02:04.340
Or the rest of it.

02:04.840 --> 02:09.700
And it's super cool.

02:09.940 --> 02:21.410
It's.

02:21.800 --> 02:25.200
It's finally the area

02:39.450 --> 02:45.570
that one thing will need is the constant

02:48.030 --> 02:54.560
in say double and PI B pt. 2.

02:54.570 --> 02:56.870
Calculate all these things.

02:57.060 --> 03:02.240
Point 1 4 1 9 is good enough.

03:02.240 --> 03:03.010
So nos.

03:03.020 --> 03:08.250
I'm creating this outside of the main function.

03:08.270 --> 03:15.740
This makes it so that's it's global to the entire program.

03:15.740 --> 03:19.160
And this is a constant not a variable.

03:19.160 --> 03:26.960
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

03:26.960 --> 03:28.270
going to change.

03:28.580 --> 03:30.670
It's not a problem.

03:30.750 --> 03:36.210
So now it's right the functions

03:48.440 --> 04:02.070
this so if you remember the diameter is really just two times that radius Sancy two point o time radius.

04:02.490 --> 04:18.060
And that's all there is for that on the circumference is two times the radius times Pi or so you get

04:18.060 --> 04:21.770
the circumference of the circle the outer edge of the circle.

04:22.290 --> 04:26.260
And finally the area is

04:30.380 --> 04:30.790
I

04:33.340 --> 04:35.390
times the radius square right.

04:38.400 --> 04:38.910
That's it.

04:39.760 --> 04:41.280
So it's run this

04:49.030 --> 04:49.880
time.

04:51.400 --> 05:00.760
Five say and diameter is 10 conferences three point four something.

05:01.090 --> 05:05.230
And the area is seventy eight point five three nights.

05:07.330 --> 05:24.320
Is just going over some simple return value and parameters and that's it so the next problem is write

05:24.330 --> 05:33.390
a function that gets an integer from the user and do all the appropriate error checking.

05:33.390 --> 05:44.330
So we've kind of already seen this before and let's just comment stuff.

05:45.390 --> 05:46.390
OK.

05:46.630 --> 05:51.730
So let's write a function or to name it.

05:54.640 --> 05:58.060
So it's going to turn an integer and C gets integer

06:02.070 --> 06:03.610
user and

06:06.260 --> 06:08.120
that's going to be the name of it.

06:09.470 --> 06:14.600
So we saw this before in the last section with looping.

06:14.900 --> 06:21.820
So it's really asked us to do is take all that and then put it into a function.

06:22.010 --> 06:31.320
So it's going to return an integer and there's going to be no parameters.

06:31.460 --> 06:40.280
So I told you we're going to be returning to input again and again and we're still going to see some

06:40.280 --> 06:45.410
more input examples in the next two maybe three sections.

06:45.470 --> 06:50.810
So let's just write that definition of get integer

06:53.440 --> 07:00.440
integer and user call that right.

07:01.080 --> 07:08.190
So if you remember it's just have a Boolean for if we failed.

07:08.380 --> 07:14.490
So if the user typed in something incorrectly we're going to set that boolean to true

07:17.010 --> 07:18.450
integer for the number.

07:18.480 --> 07:28.510
Remember we're in use the do while loop you while while there's a failure rate.

07:28.840 --> 07:30.420
So we want to keep doing.

07:30.510 --> 07:37.960
Want to keep prompting the user as long as there is a failure and we set the failure to be false.

07:38.790 --> 07:44.680
At the start because at the start of the loop there is no failure rate.

07:46.420 --> 07:51.290
He's chair integer

07:56.560 --> 07:58.850
mirror.

07:59.160 --> 08:05.720
If so if you remember if there there's a failure we say see and fail on it.

08:05.860 --> 08:15.130
Now evaluate to true if we are in the failure state and we have to clear that state and then ignore

08:15.850 --> 08:18.220
any of the harmful

08:21.010 --> 08:28.960
effects we probably need another fiery here counts.

08:29.350 --> 08:32.760
Nor shoppers

08:35.560 --> 08:39.380
sex it by the way.

08:39.410 --> 08:46.350
256 is just kind of arbitrary is really Nannar probably put it to maybe even higher.

08:46.390 --> 08:59.560
If I could and it ignores that many number of characters up until a new line in or is going to output

09:00.140 --> 09:01.220
as input air

09:03.890 --> 09:06.720
in or is it just please try it.

09:12.150 --> 09:16.810
And if the set the failure flag to be true.

09:20.750 --> 09:33.520
There was a failure in this case then we have to do is return the integer number and here in the main

09:33.520 --> 09:34.690
reason to say

09:37.380 --> 09:47.950
the number number is called to get ger for my user

09:50.810 --> 10:00.180
bat and we're going to print out the number and number you got us

10:04.200 --> 10:04.590
number

10:10.780 --> 10:13.400
so sag and Fred.

10:13.600 --> 10:16.260
So he says please try again.

10:16.440 --> 10:17.660
So it's wrong.

10:17.670 --> 10:20.750
Some random garbage that's wrong.

10:21.160 --> 10:23.760
And 10 you got the number 10.

10:24.040 --> 10:25.000
OK.

10:25.000 --> 10:30.910
So if you're wondering why I keep harping on this example of the input it's because I really don't need

10:31.510 --> 10:38.750
input in the next section which is finally where are you going to make the game.

10:39.010 --> 10:48.120
So and to do that we need to have proper input and you'll see exactly what I mean when we start our

10:48.120 --> 10:48.570
game.

10:48.660 --> 10:57.690
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

10:57.690 --> 10:58.510
make a game.

10:58.530 --> 11:04.310
And after after that we'll be making a lot more games more frequently.

11:04.320 --> 11:11.650
So so joining me in the next section and watch actually star start actually doing our projects.
