We're at the end of this section so that means we should be doing some practice now and in the next
lecture there'll be some practice problems for you to do alone.
So I hope you do these practice problems because the more you practice the better you'll get at it.
And if you're always just following someone else you'll really solidify what you've been learning.
So let's start with Problem 1 here.
It says right now a that takes the temperature in Fahrenheit and outputs it in Celsius.
So it's kind of like what we had before except for the reverse.
Before we add Celsius to Fahrenheit now we're having Fahrenheit to Celsius.
So let's have a variable called Loach Celsius and reason float because since we have to divide something
if you remember your formula for Fahrenheit to Celsius as I'm sure you all do you have to actually divide
some numbers so we're going use float so we can have better precision.
So then in hi it's
in touch.
So say see out
please enter the Fahrenheit.
See in the Fahrenheit
and then calculate the Celsius
Celsius is
at night which minus 30 to times.
Thirty two point to Earth 5.0 and we use five point oh here and this should make sure that everything's
all in floating point number numbers.
9.00 that's the formula.
And we'll just put it.
See Ouch.
We'll see if Fahrenheit.
Ch
in Celsius is
Celsius.
And so we're on it.
And stay
hopper here.
We're on
say 70 should be about 21 degrees Celsius and that's it for this one.
So the next one actually we're going to
comment every line so you can do it.
The next problem
write a program that takes three numbers and prints the average So we need three numbers.
All Again we'll use float here use integer if you really want.
But just for precision sake use float 3.
So we have three C out say please enter three numbers
paraded Speace.
Rules change in all.
One two in three
and safe Loach average is one plus two plus three.
Nice room using parentheses here just like we did in the last problem.
Just to make sure that everything gets done in the proper order.
C Ouch.
The average
is in print.
The average
is like are Kirkley
it's kind of weird sometimes.
You know
32 Phi.
He didn't five say so.
The average is 15.
That's it in comment.
Ouch.
And
it's gone the next problem is kind of interesting and it'll it'll kind of use something that we went
over in the types lecture so it says write a program that takes in a character and outputs its ascii
value.
So sure you all looked at the table the ASCII table so you all know what the ascii values are now.
So let's first get the actual character input so say see out leads enter a character
that's seat in the character input.
And let's let's do let's do it like this.
Let's say we have an int and we'll call it value and we're going to sign it.
The char input and remember what I said that it's.
It can be sometimes dangerous to do this but in fact this happens actually quite a bit.
This is what's called casting.
So we're casting this char input into which is a char into a integer.
And this is actually OK here because the int is much bigger than a char.
So in in essence we're never going to be losing any information.
For example if we had some kind of Intan then or a double at say and cast that to a float we might lose
precision.
In fact we probably will lose precision but in this case this is acceptable.
So let's just output seek out ch
s e
value.
Our input.
Is
now in
it's run.
I don't understand why Eclipse does sometimes.
So enter Charlotte S. capital A.
So you ask the value of A is 65.
So if you look up the ASCII table right now and you can actually check yourself and it is indeed 65
so you can even read this again and see.
So if he entered B it should be 66 ranked it is.
So this is working correctly.
So just a few examples of problems that he could come across later on.
In fact we'll come across much much more difficult problems.
But I want to start you off nice and easy trying to get you familiar with the syntax and how things
are really working.
And I hope you'll do the next lecture which is a an article of just more problems to solve and I hope
you will take the time and figure them out and try them in in Eclipse and run them and see what kind
of output you can get.
So I'll see you in the next section.