Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,490 --> 00:00:07,000
So before we move on, I want to show you guys how using your input will look like in real code and
2
00:00:07,000 --> 00:00:11,800
how you're going to actually use the console application to reading books from the user.
3
00:00:12,130 --> 00:00:17,620
And the first example I want to give you is a simple program that reads a number from the user and then
4
00:00:17,620 --> 00:00:19,390
prints that number on the screen.
5
00:00:19,660 --> 00:00:23,950
So for that, let's first of all, create or declare a new variable.
6
00:00:24,370 --> 00:00:26,550
Let's call it Nalmefene Nahm.
7
00:00:27,040 --> 00:00:29,830
So here we just created a variable called Nahm.
8
00:00:29,830 --> 00:00:31,150
Its name is now.
9
00:00:31,450 --> 00:00:32,520
And this of tight.
10
00:00:32,700 --> 00:00:33,850
And of type end.
11
00:00:34,150 --> 00:00:34,520
All right.
12
00:00:34,820 --> 00:00:38,790
And now, just for the explanation, let's assign some value to NUM.
13
00:00:38,830 --> 00:00:42,620
For example, let's call it naoum equals to 10.
14
00:00:42,670 --> 00:00:43,240
All right.
15
00:00:43,810 --> 00:00:49,300
And before we actually use inputs to read the data from the user, we'll just use the assignment just
16
00:00:49,300 --> 00:00:49,960
to show you.
17
00:00:49,960 --> 00:00:53,020
It will be much easier for me to explain to you guys.
18
00:00:53,280 --> 00:00:55,750
And now I want to print this name on the screen.
19
00:00:55,760 --> 00:01:00,140
So for that, I'm going to use print Taffe and just print narm.
20
00:01:00,880 --> 00:01:08,260
Is percentage the ampersand can and just replace the percentage with the nom itself.
21
00:01:08,440 --> 00:01:08,830
Right.
22
00:01:08,830 --> 00:01:10,120
Semicolon at the end.
23
00:01:10,480 --> 00:01:11,150
We'll save it.
24
00:01:11,390 --> 00:01:15,070
And now if we are to run this program, let's build and run it.
25
00:01:15,250 --> 00:01:18,870
You can see right here in the console application Nahm is found.
26
00:01:18,880 --> 00:01:19,270
All right.
27
00:01:19,300 --> 00:01:20,590
We'll learn of it so far.
28
00:01:20,620 --> 00:01:26,500
That print half prints, some message, some text to the screen, to the console application in our
29
00:01:26,500 --> 00:01:27,040
example.
30
00:01:27,340 --> 00:01:28,690
So NARM is ten.
31
00:01:28,960 --> 00:01:29,450
Great.
32
00:01:29,530 --> 00:01:33,760
So now if we run this program once again, let's run it once again.
33
00:01:34,150 --> 00:01:36,600
We can see that the result is going to be the same.
34
00:01:36,610 --> 00:01:43,420
And if we run it once again, the result is also always going to be Nahm is standing in such a case.
35
00:01:43,470 --> 00:01:43,870
All right.
36
00:01:44,140 --> 00:01:49,870
Even if you run it a hundred times or give the program to different users, you will still get the same
37
00:01:49,870 --> 00:01:50,470
result.
38
00:01:50,920 --> 00:01:58,030
And the reason is that you assign their value to narm insert a free hardcoded manner Naam equals to
39
00:01:58,030 --> 00:01:58,390
ten.
40
00:01:58,690 --> 00:02:06,040
So now we will not assign a value of ten, but rather we are going to give the user the ability to insert
41
00:02:06,040 --> 00:02:07,930
the value on itself.
42
00:02:08,320 --> 00:02:11,920
And you can do that by first of all, removing the base assignment.
43
00:02:11,950 --> 00:02:12,120
OK.
44
00:02:12,250 --> 00:02:17,670
Now he's not equals to ten to ten anymore and we'll just use the scanner function.
45
00:02:17,680 --> 00:02:21,910
So scan F exactly as we've seen in the previous video.
46
00:02:22,710 --> 00:02:26,170
The percentage D because we are reading an integer.
47
00:02:26,280 --> 00:02:26,550
Right.
48
00:02:27,040 --> 00:02:30,570
And we are going to put it inside of numbers.
49
00:02:31,030 --> 00:02:31,480
All right.
50
00:02:31,510 --> 00:02:36,580
The ampersand specifies the address where these variable nahm resides.
51
00:02:36,910 --> 00:02:44,140
Now if we build and run it, we can see these kind of prong to these console application that expects
52
00:02:44,140 --> 00:02:45,910
you to insert some value.
53
00:02:46,330 --> 00:02:49,290
So let's just insert let's make it five or.
54
00:02:49,290 --> 00:02:49,720
All right.
55
00:02:49,930 --> 00:02:56,890
And once you hit the enter button, the value itself you've just specified is going to be inserted in
56
00:02:56,890 --> 00:02:58,310
this variable num.
57
00:02:58,430 --> 00:02:58,630
Right.
58
00:02:58,840 --> 00:03:04,870
It's going to read it from this console application, from this prompt and just put it inside of this
59
00:03:04,870 --> 00:03:06,000
num variable.
60
00:03:06,010 --> 00:03:07,120
So press enter.
61
00:03:07,510 --> 00:03:08,340
And there you go.
62
00:03:08,350 --> 00:03:13,090
You can see the message num is five, Nahmias five printed out on the screen.
63
00:03:13,420 --> 00:03:16,090
So now if you try to round this program once again.
64
00:03:16,140 --> 00:03:17,340
Let's do it once again.
65
00:03:17,350 --> 00:03:17,840
Run.
66
00:03:17,890 --> 00:03:19,320
And just insert here.
67
00:03:19,360 --> 00:03:19,840
I don't know.
68
00:03:20,260 --> 00:03:21,040
A hundred.
69
00:03:21,430 --> 00:03:21,880
All right.
70
00:03:21,880 --> 00:03:25,600
So the result is going to be different than the previous one.
71
00:03:25,870 --> 00:03:30,160
So now we will get this one hundred once we press the enter button.
72
00:03:30,580 --> 00:03:34,630
We will get this one hundred inside of this num variable.
73
00:03:34,960 --> 00:03:38,200
And then we are going to see Naoum is a hundred.
74
00:03:38,230 --> 00:03:39,590
So let's check this out.
75
00:03:39,610 --> 00:03:40,390
Press enter.
76
00:03:40,630 --> 00:03:41,320
And there you go.
77
00:03:41,320 --> 00:03:43,250
You can see NUM is a hundred.
78
00:03:43,510 --> 00:03:48,910
And that's how you use variables and how you use inputs in C programming language.
79
00:03:49,630 --> 00:03:53,650
This simply means that we created a more generic program.
80
00:03:53,690 --> 00:03:54,340
They're different.
81
00:03:54,520 --> 00:04:00,220
Users may use it and insert different values and we'll see in the next examples.
82
00:04:00,310 --> 00:04:04,570
Why is it so useful as well as not only in the next examples?
83
00:04:04,570 --> 00:04:07,720
We will see it also during the whole course.
6819
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.