WEBVTT

00:00.920 --> 00:08.240
We're at the end of this section so that means we should be doing some practice now and in the next

00:08.240 --> 00:14.130
lecture there'll be some practice problems for you to do alone.

00:14.210 --> 00:21.220
So I hope you do these practice problems because the more you practice the better you'll get at it.

00:21.350 --> 00:28.840
And if you're always just following someone else you'll really solidify what you've been learning.

00:29.180 --> 00:32.850
So let's start with Problem 1 here.

00:32.960 --> 00:40.090
It says right now a that takes the temperature in Fahrenheit and outputs it in Celsius.

00:40.100 --> 00:45.220
So it's kind of like what we had before except for the reverse.

00:45.230 --> 00:50.290
Before we add Celsius to Fahrenheit now we're having Fahrenheit to Celsius.

00:50.470 --> 01:02.410
So let's have a variable called Loach Celsius and reason float because since we have to divide something

01:02.930 --> 01:10.690
if you remember your formula for Fahrenheit to Celsius as I'm sure you all do you have to actually divide

01:11.680 --> 01:19.790
some numbers so we're going use float so we can have better precision.

01:19.860 --> 01:23.500
So then in hi it's

01:26.890 --> 01:28.210
in touch.

01:28.240 --> 01:30.290
So say see out

01:32.840 --> 01:40.590
please enter the Fahrenheit.

01:45.800 --> 01:47.550
See in the Fahrenheit

01:51.810 --> 01:54.280
and then calculate the Celsius

01:58.060 --> 01:59.770
Celsius is

02:02.490 --> 02:09.460
at night which minus 30 to times.

02:09.460 --> 02:22.790
Thirty two point to Earth 5.0 and we use five point oh here and this should make sure that everything's

02:22.790 --> 02:26.120
all in floating point number numbers.

02:28.700 --> 02:32.780
9.00 that's the formula.

02:33.080 --> 02:34.550
And we'll just put it.

02:34.650 --> 02:37.300
See Ouch.

02:37.360 --> 02:38.790
We'll see if Fahrenheit.

02:38.820 --> 02:39.270
Ch

02:42.140 --> 02:46.810
in Celsius is

02:50.240 --> 02:51.280
Celsius.

02:55.910 --> 03:00.270
And so we're on it.

03:04.180 --> 03:05.670
And stay

03:09.200 --> 03:10.190
hopper here.

03:15.630 --> 03:16.380
We're on

03:20.420 --> 03:34.540
say 70 should be about 21 degrees Celsius and that's it for this one.

03:34.630 --> 03:38.320
So the next one actually we're going to

03:41.950 --> 03:54.200
comment every line so you can do it.

03:54.230 --> 03:55.090
The next problem

03:58.450 --> 04:03.810
write a program that takes three numbers and prints the average So we need three numbers.

04:03.810 --> 04:07.760
All Again we'll use float here use integer if you really want.

04:07.770 --> 04:15.290
But just for precision sake use float 3.

04:15.500 --> 04:24.760
So we have three C out say please enter three numbers

04:27.180 --> 04:35.960
paraded Speace.

04:36.160 --> 04:39.220
Rules change in all.

04:39.990 --> 04:44.420
One two in three

04:47.690 --> 05:02.100
and safe Loach average is one plus two plus three.

05:02.200 --> 05:06.280
Nice room using parentheses here just like we did in the last problem.

05:06.280 --> 05:12.990
Just to make sure that everything gets done in the proper order.

05:13.040 --> 05:14.430
C Ouch.

05:17.790 --> 05:19.380
The average

05:21.650 --> 05:25.410
is in print.

05:25.440 --> 05:26.160
The average

05:37.310 --> 05:38.830
is like are Kirkley

05:45.380 --> 05:46.830
it's kind of weird sometimes.

05:48.130 --> 05:48.640
You know

05:51.330 --> 05:53.830
32 Phi.

05:53.870 --> 05:57.680
He didn't five say so.

05:57.730 --> 06:02.430
The average is 15.

06:02.590 --> 06:06.200
That's it in comment.

06:06.300 --> 06:07.270
Ouch.

06:09.250 --> 06:09.970
And

06:13.380 --> 06:22.090
it's gone the next problem is kind of interesting and it'll it'll kind of use something that we went

06:22.090 --> 06:34.210
over in the types lecture so it says write a program that takes in a character and outputs its ascii

06:34.210 --> 06:35.230
value.

06:35.580 --> 06:44.390
So sure you all looked at the table the ASCII table so you all know what the ascii values are now.

06:44.500 --> 07:00.710
So let's first get the actual character input so say see out leads enter a character

07:04.830 --> 07:12.490
that's seat in the character input.

07:14.140 --> 07:16.870
And let's let's do let's do it like this.

07:16.900 --> 07:21.490
Let's say we have an int and we'll call it value and we're going to sign it.

07:21.490 --> 07:27.460
The char input and remember what I said that it's.

07:27.460 --> 07:34.770
It can be sometimes dangerous to do this but in fact this happens actually quite a bit.

07:34.810 --> 07:37.350
This is what's called casting.

07:37.810 --> 07:45.660
So we're casting this char input into which is a char into a integer.

07:45.790 --> 07:51.970
And this is actually OK here because the int is much bigger than a char.

07:52.060 --> 07:58.790
So in in essence we're never going to be losing any information.

07:58.840 --> 08:05.800
For example if we had some kind of Intan then or a double at say and cast that to a float we might lose

08:05.800 --> 08:07.020
precision.

08:07.030 --> 08:12.320
In fact we probably will lose precision but in this case this is acceptable.

08:12.310 --> 08:18.110
So let's just output seek out ch

08:22.760 --> 08:23.980
s e

08:31.150 --> 08:32.900
value.

08:35.420 --> 08:37.260
Our input.

08:40.170 --> 08:40.950
Is

08:44.180 --> 08:47.070
now in

08:57.720 --> 09:00.990
it's run.

09:03.240 --> 09:06.970
I don't understand why Eclipse does sometimes.

09:07.690 --> 09:10.770
So enter Charlotte S. capital A.

09:11.200 --> 09:15.190
So you ask the value of A is 65.

09:15.370 --> 09:22.560
So if you look up the ASCII table right now and you can actually check yourself and it is indeed 65

09:22.570 --> 09:25.850
so you can even read this again and see.

09:25.850 --> 09:30.580
So if he entered B it should be 66 ranked it is.

09:30.670 --> 09:33.600
So this is working correctly.

09:33.640 --> 09:41.290
So just a few examples of problems that he could come across later on.

09:41.290 --> 09:44.370
In fact we'll come across much much more difficult problems.

09:44.380 --> 09:51.160
But I want to start you off nice and easy trying to get you familiar with the syntax and how things

09:51.160 --> 09:52.380
are really working.

09:52.840 --> 10:00.700
And I hope you'll do the next lecture which is a an article of just more problems to solve and I hope

10:00.700 --> 10:09.110
you will take the time and figure them out and try them in in Eclipse and run them and see what kind

10:09.110 --> 10:10.960
of output you can get.

10:10.970 --> 10:12.960
So I'll see you in the next section.
