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
What is going on, guys?
And in this video, we're going to talk about how to use variables in C programming language.
We are going to talk about variables, declaration, variables, assignment, and also how to read an
input from the user.
So in the previous media, we've talked about how variables are similar to boxes.
Now let's understand how we can create variables.
So let's introduce the variables declaration.
This will usually be the first step for working with variables.
And that makes sense because variable declaration is the same as box creation.
So variable declaration is equivalent to variable creation and it simply states that you just create
some variable in the memory of your computer.
And how do you create a variable in C language?
The structure is very straightforward.
First of all, you specify the type of the variable and then you specify its name.
And of course, at the end you add a semicolon.
For example, if we wanted to create a variable of type integer that will store our age, we would first
of all specify its type, which is Ent., and then specify its name, for example, age.
So we have a variable named age and it is of type end.
So once again, this way you created a variable called age and it's of type int to hald integer values.
And let's say you wanted to create a variable of type double, which is used to hold floating point
values.
So in this case, the type of the variable and the declaration phase should be specified as double.
Then in the same way we will give this variable and name, for example, temp, which will be used to
hold the temperature in Celsius or foreigner degrees.
So just use double temp.
Double is the type.
Temp is the name of the variable and the semicolon at the end to specify that we've done with our variable
declarations.
So this structure for creating variables in ceiling, which will be pretty much always the same.
You first of all, specify the type of the variable to be created.
Then you specify the variables name.
And at the end, of course, you add a semicolon.
So to summarize this thing a little bit, whenever you want to work with a variable, you need, first
of all, to create it.
And how can you created by using variable declaration, specify its type.
Then give its name at a semicolon at the end.
And your variable is ready to go.
So now let's talk about an assignment operation.
So once you have your variable, you may want to put something inside of it, right?
Simply to let it hold some value.
That's what variables are all about.
And this operation, when you want to put some value in a variable, is called an assignment to assign
some value to a variable.
So how should it be done in our C programming language?
The variable itself has a type either or that's an integer, a floating point, a character or what
not.
And in most cases, we will put inside of that variable some value that matches the variables type.
So how will it look like in C?
Previously would declare were created two variables.
The first one was age.
And the second one was temperature.
And we can see that the variable ages of type end.
Right?
We can see it in the declaration face and age.
That means we expect to assign it a value of an integer type.
For example, 30.
So that's why we use age equals to 30.
And we can see the assignment simply taking the value of its right.
Which is 30 and placing it into the variable called age on its left.
A variable which we declared.
Just one line above.
So as simple as that.
Just the sign of value to a given variable.
And you can do pretty much the same for also the variable term.
Which we declared using double temp.
You can assign it a value of twenty six point five four temperature in Celsius or seventy six point
point seven if you're using Fahrenheit, which is the same temperature, adjusting different units.
And you can see that the values are floating point numbers.
We're using these Daudt thing, these twenty six point five.
DOT five.
This indicates that this number is a floating point.
And that's OK because we declared the temperature variable as type double to hold floating point numbers.
All right.
And by the way, in your next milestone, you're going to develop a program that will be capable of
making these conversion between temperature given in Celsius to foreign aid degrees and vice versa.
You're going basically to develop a weather station program, but we'll get to that later on in this
chapter.
So to summarize, for now, the first step will usually be to create word, declare a variable.
Well, and the second step will be to put something in that variable or simply sink to assign some value
to a given variable.
And now we're going to talk about a very important part in this section.
And it's called reading input from user or variable is input.
And that's a really important part.
Guys, it simply explains how your program can be reading data or information from the user really much
as you use forums that you feel on a Web site.
The program that runs in the back end reads, Every field of this form and store is 18 variables.
And up to this point, we've learned how to create variables in how to use assignments to.
They are most part of our program.
And now what we would like to do is to get the value from the user instead of using the assignment operator.
The assignment was done as part of our program, which means we simply used some hard coded assignment
and we set a value to a variable without the ability to give the user.
We are the developers, right.
And we also have the users without providing the user with the ability to enter to insert its value
to that variable.
We simply declared it and then assigned it a given value.
For example, a grade is equal to 30.
And what is the problem with that?
Basically, there is no problem with using any of them.
There is only a difference between when one should be used over the other.
So once again, there may be cases where we would like to use assignment operator and there may be other
cases when you will need to use the input thing to get some information directly from the user.
As we are going to see in the following examples.
So suppose you have to write down a program that should calculate the average of two grades.
One way to do so would be to refine these two variables by using the assignment operation to set their
values to, let's say, grade one equals to 80 and grade two equals to a hundred.
First of all, we know that an average of two grades can be calculated.
But summing both of them and dividing the sum by two.
So the average would be simply 80 plus seeing a hundred divided by two, which gives us a total of 90.
So we can simply use a print command to print the screen.
That average equals two percentage D, and instead of these presenters will just replace it with a total
of 90.
Right.
They are the expression that on the right of the comma.
That's great.
It would work.
But in this example, we define the two rates.
We as the developers.
We've simply created a program that will always print the average for these specific grades.
One read one equals two 80 and grade two equals to a hundred.
And I guess you noticed that this program is not generic.
It will always print the average 90, always print the same.
Unless we manually change the grades.
And in such a case, we simply cannot sail or ship this program to customers because the program does
not know anything except these two rates.
Eighty and hundred.
We want to give the user the ability to insert his own grades and then our program will calculate the
average grade and give the result to the user.
And that's exactly why we learn to work with the inputs.
Now let's take a look at the syntax of how that should be done in our C programming language.
So we we want to create a program that calculates the average grade of two given grades.
We, first of all, need to declare these two variables.
So we created a grade one.
And also we create grade two.
And at this point, these two variables are kind of empty.
We say that they contain garbage value that can not be used.
And we could assign some values to them like we've seen previously.
Something like Ridwan equals two, 80 and grade two equals to 100.
But that's not exactly what we want to do.
What we want to do is to read the grades from the council, to read the grades from the user.
We want to let the user to provide his own grades.
So then any user will be able to use our program with his own grades.
And to do so, we'll use one little function that will help us with that.
And this function is called.
So that syntax in C language for the input of the first grade looks like this scan F percentage, the
on percent grade one.
Don't panic just yet.
Let's try to understand the structure of this comment together.
These functions simply reads the value we inserting the council.
And we first of this value as an integer.
That's why we have this percentage D.
Right.
Just like we used percentage the in the print F comment to print something to the council.
Now we are reading from the console.
The input that the user will provide us with.
And we treated.
As an integer, thanks to these percentage deals, pretty simple, right?
And the value itself will be stored inside of grade one variable, which we've just created.
And these sampas and sign, all it does is to specify that the value read from the console using these
percentages, they should go and be placed at the address where grade one resides.
So once again, read an integer from the console and put it in the address where grade one resides,
or simply put, this value in grade one variable.
So pretty much the same way we'll do this for a grade two.
So now at this point, we have two variables grade one and grade two.
And they hold the grades that the user just provided.
Using these console.
And now let's print the average of them on the screen.
There are actually a couple of ways that we can do it.
One of them is just to write the mathematical operation in one print off-line.
Something like that print F average equals two percent percentage day.
And then to write the mathematical operation as we've seen previously.
And there you go.
Your average grade should be printed on the screen.
Average equals to 19.
In our case.
Pretty cool, right?
Threats around this code on your own.
Open code blocks or visual studio or wherever.
I'd use and try to run this code on your own and see how it works for you.
One thing to mention here is that we didn't speak about anything related to casting, and that's actually
the result of dividing the sum of your grades by two.
This result may be actually a floating point.
Number is something like ninety seven point and Dinara case.
It won't be printed correctly.
The only thing that will be printed on the screen will probably be just 97.
It will be just rounded.
So one of the ways to handle that is to use casting.
But for now and for this video, I think that's enough.
I hope you got the idea of how the functions SCAF works and that you are ready to move on for your next
challenges.
Where we will practice that even more.
So I wish you good luck, guys.
And I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.