Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Welcome back.
So in this video, we will solve the problem of getting from point A to point B..
OK, so what we will do is simply to initialize two variables, which are the distance between, let's
say, 18 kilometers units.
And also we'll have that the speed that the vehicle is going to be driving.
So we have the speed.
Also, let's say in terms of kilometers per hour, for example.
OK, so if it's not kilometers per hour or maybe some other unit, of course, it may be also calculated
using other units.
I'm going to use the distance as the kilometers and the speed is kilometers per hour.
And once we know the distance and the speed, we will we should calculate the time that it should take
vehicle, our vehicle, our car to reach from city to city B so time in this case will be equal to what?
So we know that first of all, let's say we know that distance distance equals to speed multiplied by
time.
Right.
So if you drive at some speed and you multiply it by time, you will get the distance that you will
pass.
So just by modifying this equation a little bit, we will get that.
Time equals distance divided by speed.
So distance the distance divided by speed.
So that's the formula that we are going to use to calculate the result of the calculate the actual time
that it will take to reach from city to city B..
And we are requested to initialize these very these variables.
So for that, we will simply use distance and the distance is going to be something like, I don't know,
300 kilometers, OK, kilometers.
And also we will have the speed is something like, I don't know, 75 kilometers per hour.
OK, so why meters per hour?
That's the speed of the vehicle.
And if we will use here time, OK, we can say that time equals to distance distance divided by speed.
Right.
We have here our formula time equals the distance divided by speed.
We already explain it and the time itself is going to be in what units?
It's going to be in our units hours, how many hours it took to reach from point A to point B..
So if we will ride to the solution like this or half the time for driving from A to B, we'll take,
I don't know, percentage these powers.
Right.
And here, of course, let's just minimize it a little bit.
Instead of the percentage placeholder, we will use time, right?
So awesome, so the time for driving from A to B will take a percentage these hours.
So if we divide distance by speed, we will get three hundred divided by seventy five, which is, if
I'm not mistaken, just four hours.
OK, so let's build and run this program to make sure that it works exactly as we expected.
Yeah.
So the time for driving from A to B will take four hours if you drive it.
Seventy five kilometers per hour and you do it and the distance is three hundred kilometers.
But it's very important to notice here and basically for you to understand is that this answer is not
entirely correct, since it's not necessary that the time will be exactly four hours on the clock.
The time may also consist of minutes, right.
The time may be also like four hours and 10 minutes, four hours and 20 minutes.
He doesn't necessarily have to be some integer.
Right, for example, represented just in terms of hours.
So how should we also calculate the minutes that it took us to drive from point A to point B so that
finally the result will be represented like he took us four hours and 10 minutes to reach from point
A to point B?
OK, so basically this calculation time equals distance divided by speed.
It will give us just the the integer, just the the total hours, the full hours it took us to drive.
But if, for example, we had, I don't know, speed instead of seventy five, even the speed was 80
then what should be pointed to the screen now.
Because we know that if we divide 300 by eight then it simply will be three hundred divided by eight.
It will simply give us what will be three.
Right.
Three hours.
Three total hours because time is of an integer type.
So three hundred divided by eight will give us three hours.
But what about the remaining three hours.
Took us to complete two hundred and forty kilometers.
What about the other 60 kilometers that were left.
How should we calculate them.
Basically we know that 60 kilometers it will take us less than an hour to complete.
It will take us about 40 minutes.
Something like this, 30 minutes, 40 minutes to complete.
So how we should also calculate the timing hours.
So first of all, what I suggest to do is to modify this variable and to call it instead of time, probably
hours.
OK, that's the total amount of hours they took to complete a given portion of the distance.
And also what we should do is to create additional variable speeds flow.
So float speed in minutes.
Basically, that's the remaining speed and it will be equal to let's say, no, it's not.
Let's use speed in minutes, not for the remaining part of the minutes, but rather just to calculate
the speed.
OK, just the calculator.
That was my mistake, just to calculate the speed in minutes.
So we have here the information that the speed per hours equals to this one, right.
Kilometers per hour.
And what I want us to do now is simply to represented this how many kilometers we will pass in a minute.
So for that, we simply take the speed, the previous speed and divided by 60.
And this will give us the speed.
OK, the total amount of kilometers per minute.
OK, so if we do gusts are 80 kilometers per hour and now it will take us eighty divided by 60 kilometers
per minute.
And I only remember what it is.
It's kind of one point three three three kilometers per minute.
So once you have this information, what we will have to do is to create additional variables.
For example, minutes, remaining minutes, let's call it even this way, the remaining minutes, right.
So remaining remaining remaining minutes.
And once we have the remaining minutes, we know that, first of all, what we will take is the remainder
of the distance divided right for speed, OK, which is simply the 60 kilometers we have previously.
And how how many minutes, OK, how many minutes did it take us to complete?
OK, the distance, that's the distance that left OK there.
For example, if we had three hundred kilometers, so three hours, four hours, we passed two hundred
and forty kilometers and all that's left is three hundred minus two hundred and forty, which is 60
kilometers divided by the speed in minutes, the speed in minutes.
And in this case, what we will get is the result of the remaining minute units.
And finally you give everything was OK.
So the time for driving the time, let's say, from A to B will take percentage hours and percentage
DKK minutes and here will specify the hours and the remaining minutes.
OK, guys, so I hope it's clear to you as to why we're using that.
So let's let's just build and run it and see for ourselves that everything is working as expected.
So the time from A to B will take three hours and 44 minutes.
I think that something was with the with the casting here, but yeah, it should be.
Yeah.
So, yeah, it's very strange why we got here.
Forty four minutes instead of forty five minutes.
Something probably got missing with the grounding, so let's maybe try to find it out and.
Oh yeah, it's probably here, it's rounded up to forty four and the reason is very simple because here
we have distance and speed divided by speed which gives us an integer in this case divided by a floating
point, and the result is a floating coin type.
So basically we can use it here not to complicate everything for this exercise, like she is here to
float remaining minutes and here he is, percentage F, OK, and in this percentage, two point two.
So let's build in running just to make sure that everything works as expected.
So the time for me to be will take three hours and forty five minutes, which is exactly the result
we expected to receive.
So it was not easy I guess, but ah I think you kind of understood what I meant and that the previous
some, some of the basic explanations that some of them, the tutorials that I've seen that they don't
take into account the minutes.
And also we can also take here the seconds into account if we want to be really precise.
But do not take just the few hours, take the portion of the hours as well as taking the portion of
the minutes.
And that's the way how you do it when you define a variable hours, taking the full hours out of the
distance that it takes you to bef.
So the full hour is three hours and then you take the remainder off of what is left for you and divide
it by speed and minutes in order to get the time in minutes units.
OK, so for that you calculated how what is your speed and kilometers per minute.
Once you get the remaining minutes, you simply print the result to the screen.
So as always, thank you so much for watching.
Keep on practicing.
You're improving.
Also, we are recovering a lot of interesting things here.
So until next time, I'll see you in the next videos.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.